aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThierry Vignaud <tv@mandriva.org>2007-02-20 14:01:59 +0000
committerThierry Vignaud <tv@mandriva.org>2007-02-20 14:01:59 +0000
commit97d5c3d6aee14c8cd201de9dab65311d53355073 (patch)
tree17e79773ce3883288bf06f305fd0fc6ac2189bf7
parent2659811fb6c849f2a10be546fffea4eb6e505a17 (diff)
downloadrpmdrake-97d5c3d6aee14c8cd201de9dab65311d53355073.tar
rpmdrake-97d5c3d6aee14c8cd201de9dab65311d53355073.tar.gz
rpmdrake-97d5c3d6aee14c8cd201de9dab65311d53355073.tar.bz2
rpmdrake-97d5c3d6aee14c8cd201de9dab65311d53355073.tar.xz
rpmdrake-97d5c3d6aee14c8cd201de9dab65311d53355073.zip
(run_treeview_dialog) split it into smaller functions and move all of them into Rpmdrake::gui
-rw-r--r--Rpmdrake/gui.pm485
-rwxr-xr-xrpmdrake484
2 files changed, 490 insertions, 479 deletions
diff --git a/Rpmdrake/gui.pm b/Rpmdrake/gui.pm
index a7e24ae7..221d56f7 100644
--- a/Rpmdrake/gui.pm
+++ b/Rpmdrake/gui.pm
@@ -31,10 +31,113 @@ use common;
use mygtk2 qw(gtknew); #- do not import gtkadd which conflicts with ugtk2 version
use ugtk2 qw(:helpers :wrappers);
+use rpmdrake;
+use Rpmdrake::formatting;
+use Rpmdrake::init;
+use Rpmdrake::icon;
+use Rpmdrake::pkg;
+use Rpmdrake::icon;
use Gtk2::Gdk::Keysyms;
-our @EXPORT = qw(ask_browse_tree_info_given_widgets_for_rpmdrake);
+our @EXPORT = qw(ask_browse_tree_info_given_widgets_for_rpmdrake build_tree callback_choices closure_removal do_action get_info is_locale_available pkgs_provider reset_search switch_pkg_list_mode
+ $clear_button $dont_show_selections $find_entry $force_displaying_group $force_rebuild @initial_selection $pkgs $size_free $size_selected $urpm);
+our $dont_show_selections = $> ? 1 : 0;
+
+our ($descriptions, %filter_methods, $force_displaying_group, $force_rebuild, @initial_selection, $initial_selection_done, $pkgs, $size_free, $size_selected, $urpm);
+
+
+sub format_pkg_simplifiedinfo {
+ my ($pkgs, $key, $urpm, $descriptions) = @_;
+ my ($name, $_version) = split_fullname($key);
+ my $medium = pkg2medium($pkgs->{$key}{pkg}, $urpm)->{name};
+ my $update_descr = $pkgs->{$key}{pkg}->flag_upgrade && $descriptions->{$name}{pre} && $descriptions->{$name}{medium} eq $medium;
+ my $s = ugtk2::markup_to_TextView_format(join("\n", format_header($name . ' - ' . $pkgs->{$key}{summary}) .
+ # workaround gtk+ bug where GtkTextView wronly limit embedded widget size to bigger line's width (#25533):
+ "\x{200b} \x{feff}" . ' ' x 120,
+ if_($update_descr, # is it an update?
+ format_field(N("Importance: ")) . escape_text_for_TextView_markup_format($descriptions->{$name}{importance}),
+ format_field(N("Reason for update: ")) . escape_text_for_TextView_markup_format(rpm_description($descriptions->{$name}{pre})),
+ ),
+ '')); # extra empty line
+ if ($update_descr) {
+ push @$s, [ my $link = gtkshow(Gtk2::LinkButton->new($descriptions->{$name}{URL}, N("Security advisory"))) ];
+ $link->set_uri_hook(sub {
+ my (undef, $url) = @_;
+ run_program::raw({ detach => 1 }, 'www-browser', $url);
+ });
+ }
+
+ push @$s, @{ ugtk2::markup_to_TextView_format(join("\n",
+ (escape_text_for_TextView_markup_format($pkgs->{$key}{description} || $descriptions->{$name}{description}) || '<i>' . N("No description") . '</i>')
+ )) };
+ push @$s, [ "\n" ];
+ push @$s, [ gtkadd(gtkshow(my $exp = Gtk2::Expander->new(format_field(N("Files:")))),
+ gtknew('TextView', text =>
+ exists $pkgs->{$key}{files} ?
+ ugtk2::markup_to_TextView_format('<tt>' . join("\n", map { "\x{200e}$_" } @{$pkgs->{$key}{files}}) . '</tt>') #- to highlight information
+ : N("(Not available)"),
+ )) ];
+ $exp->set_use_markup(1);
+ push @$s, [ "\n\n" ];
+ push @$s, [ gtkadd(gtkshow(my $exp2 = Gtk2::Expander->new(format_field(N("Changelog:")))),
+ gtknew('TextView', text => $pkgs->{$key}{changelog} || N("(Not available)"))
+ ) ];
+ $exp2->set_use_markup(1);
+ $s;
+
+}
+
+sub format_pkg_info {
+ my ($pkgs, $key, $urpm, $descriptions) = @_;
+ my ($name, $version) = split_fullname($key);
+ my @files = (
+ format_field(N("Files:\n")),
+ exists $pkgs->{$key}{files}
+ ? '<tt>' . join("\n", map { "\x{200e}$_" } @{$pkgs->{$key}{files}}) . '</tt>' #- to highlight information
+ : N("(Not available)"),
+ );
+ my @chglo = (format_field(N("Changelog:\n")), ($pkgs->{$key}{changelog} ? @{$pkgs->{$key}{changelog}} : N("(Not available)")));
+ my @source_info = (
+ $MODE eq 'remove' || !@$max_info_in_descr
+ ? ()
+ : (
+ format_field(N("Medium: ")) . pkg2medium($pkgs->{$key}{pkg}, $urpm)->{name},
+ format_field(N("Currently installed version: ")) . find_installed_version($pkgs->{$key}{pkg}),
+ )
+ );
+ my @max_info = @$max_info_in_descr && $changelog_first ? (@chglo, @files) : (@files, '', @chglo);
+ ugtk2::markup_to_TextView_format(join("\n", format_field(N("Name: ")) . $name,
+ format_field(N("Version: ")) . $version,
+ format_field(N("Architecture: ")) . $pkgs->{$key}{pkg}->arch,
+ format_field(N("Size: ")) . N("%s KB", int($pkgs->{$key}{pkg}->size/1024)),
+ if_(
+ $MODE eq 'update',
+ format_field(N("Importance: ")) . $descriptions->{$name}{importance}
+ ),
+ @source_info,
+ '', # extra empty line
+ format_field(N("Summary: ")) . $pkgs->{$key}{summary},
+ '', # extra empty line
+ if_(
+ $MODE eq 'update',
+ format_field(N("Reason for update: ")) . rpm_description($descriptions->{$name}{pre}),
+ ),
+ format_field(N("Description: ")), ($pkgs->{$key}{description} || $descriptions->{$name}{description} || N("No description")),
+ @max_info,
+ ));
+}
+
+sub node_state {
+ my $pkg = $pkgs->{$_[0]};
+ my $urpm_obj = $pkg->{pkg};
+ #- checks $_[0] -> hack for partial tree displaying
+ $_[0] ? $pkg->{selected} ?
+ ($urpm_obj->flag_installed ? ($urpm_obj->flag_upgrade ? 'to_install' : 'to_remove') : 'to_install')
+ : ($urpm_obj->flag_installed ?
+ ($urpm_obj->flag_upgrade ? 'to_update' : 'installed')
+ : ($urpm_obj->flag_base ? '/usr/share/rpmdrake/icons/base.png' : 'uninstalled')) : 'XXX';
+}
# ask_browse_tree_info_given_widgets will run gtk+ loop. its main parameter "common" is a hash containing:
# - a "widgets" subhash which holds:
@@ -109,8 +212,8 @@ sub ask_browse_tree_info_given_widgets_for_rpmdrake {
my $s; foreach (split '\|', $root) {
my $s2 = $s ? "$s|$_" : $_;
$wtree{$s2} ||= do {
- my $pixbuf = $common->{get_icon}->($s2, $s);
- my $iter = $w->{tree_model}->append_set($s ? $add_parent->($s, $state, $common->{get_icon}->($s)) : undef, [ 0 => $_, if_($pixbuf, 2 => $pixbuf) ]);
+ my $pixbuf = get_icon($s2, $s);
+ my $iter = $w->{tree_model}->append_set($s ? $add_parent->($s, $state, get_icon($s)) : undef, [ 0 => $_, if_($pixbuf, 2 => $pixbuf) ]);
$iter;
};
$s = $s2;
@@ -121,10 +224,10 @@ sub ask_browse_tree_info_given_widgets_for_rpmdrake {
$common->{add_parent} = $add_parent;
my $add_node = sub {
my ($leaf, $root, $options) = @_;
- my $state = $common->{node_state}($leaf) or return;
+ my $state = node_state($leaf) or return;
if ($leaf) {
my $iter;
- if ($common->{is_a_package}->($leaf)) {
+ if (is_a_package($leaf)) {
$iter = $w->{detail_list_model}->append_set([ 0 => $leaf ]);
$set_node_state->($iter, $state, $w->{detail_list_model});
} else {
@@ -214,7 +317,7 @@ sub ask_browse_tree_info_given_widgets_for_rpmdrake {
};
$common->{display_info} = sub {
- gtktext_insert($w->{info}, $common->{get_info}($_[0]));
+ gtktext_insert($w->{info}, get_info($_[0], $w->{tree}->window));
$w->{info}->scroll_to_iter($w->{info}->get_buffer->get_start_iter, 0, 0, 0, 0);
0;
};
@@ -228,13 +331,13 @@ sub ask_browse_tree_info_given_widgets_for_rpmdrake {
#- not all is selected, select all if no option to potentially override
(exists $common->{partialsel_unsel} && $common->{partialsel_unsel}->(\@unsel, \@l) ? difference2(\@l, \@unsel) : @unsel)
: @l;
- $common->{toggle_nodes}($set_leaf_state, undef, @p);
+ toggle_nodes($w->{tree}->window, $w->{detail_list_model}, $set_leaf_state, undef, @p);
&$update_size;
};
my $fast_toggle = sub {
my ($iter) = @_;
gtkset_mousecursor_wait($w->{w}{rwindow}->window);
- $common->{check_interactive_to_toggle}($iter) and $common->{toggle_nodes}($set_leaf_state, $w->{detail_list_model}->get($iter, 2), $w->{detail_list_model}->get($iter, 0));
+ $common->{check_interactive_to_toggle}($iter) and toggle_nodes($w->{tree}->window, $w->{detail_list_model}, $set_leaf_state, $w->{detail_list_model}->get($iter, 2), $w->{detail_list_model}->get($iter, 0));
&$update_size;
gtkset_mousecursor_normal($w->{w}{rwindow}->window);
};
@@ -261,10 +364,374 @@ sub ask_browse_tree_info_given_widgets_for_rpmdrake {
});
$common->{rebuild_tree}->();
&$update_size;
- $common->{initial_selection} and $common->{toggle_nodes}($set_leaf_state, undef, @{$common->{initial_selection}});
+ $common->{initial_selection} and toggle_nodes($w->{tree}->window, $w->{detail_list_model}, $set_leaf_state, undef, @{$common->{initial_selection}});
#my $_b = before_leaving { $clear_all_caches->() };
$common->{init_callback}->() if $common->{init_callback};
$w->{w}->main;
}
+my ($clear_button, $find_entry);
+
+sub reset_search() {
+ $clear_button and $clear_button->set_sensitive(0);
+ $find_entry and $find_entry->set_text("");
+}
+
+sub is_a_package {
+ my ($pkg) = @_;
+ return exists $pkgs->{$pkg};
+}
+
+sub switch_pkg_list_mode {
+ my ($mode) = @_;
+ return if !$mode;
+ return if !$filter_methods{$mode};
+ $force_displaying_group = 1;
+ $filter_methods{$mode}->();
+}
+
+sub pkgs_provider {
+ my ($options, $mode) = @_;
+ return if !$mode;
+ my $h = &get_pkgs($urpm, $options); # was given (1, @_) for updates
+ ($urpm, $descriptions) = @$h{qw(urpm update_descr)};
+ %filter_methods = (
+ all => sub { $pkgs = { map { %{$h->{$_}} } qw(installed installable updates) } },
+ installed => sub { $pkgs = $h->{installed} },
+ non_installed => sub { $pkgs = $h->{installable} },
+ all_updates => sub {
+ my %pkgs = grep { my $p = $h->{installable}{$_}; $p->{pkg} && !$p->{selected} && $p->{pkg}->flag_installed && $p->{pkg}->flag_upgrade } keys %{$h->{installable}};
+ $pkgs = {
+ (map { $_ => $h->{updates}{$_} } keys %{$h->{updates}}),
+ (map { $_ => $h->{installable}{$_} } keys %pkgs)
+ };
+ },
+ );
+ if (!$initial_selection_done) {
+ $filter_methods{all}->();
+ @initial_selection = grep { $pkgs->{$_}{selected} } keys %$pkgs;
+ $initial_selection_done = 1;
+ }
+ foreach my $importance (qw(bugfix security normal)) {
+ $filter_methods{$importance} = sub {
+ $pkgs = $h->{updates};
+ $pkgs = { map { $_ => $pkgs->{$_} } grep {
+ my ($name, $_version) = split_fullname($_);
+ $descriptions->{$name}{importance} eq $importance } keys %$pkgs };
+ };
+ }
+ $filter_methods{mandrake_choices} = $filter_methods{non_installed};
+ switch_pkg_list_mode($mode);
+}
+
+sub closure_removal {
+ $urpm->{state} = {};
+ urpm::select::find_packages_to_remove($urpm, $urpm->{state}, \@_);
+}
+
+sub is_locale_available {
+ any { $urpm->{depslist}[$_]->flag_selected } keys %{$urpm->{provides}{$_[0]} || {}} and return 1;
+ my $found;
+ $db->traverse_tag('name', [ $_ ], sub { $found ||= 1 });
+ return $found;
+}
+
+sub callback_choices {
+ my (undef, undef, undef, $choices) = @_;
+ foreach my $pkg (@$choices) {
+ foreach ($pkg->requires_nosense) {
+ /locales-/ or next;
+ is_locale_available($_) and return $pkg;
+ }
+ }
+ my $callback = sub { interactive_msg(N("More information on package..."), get_info($_[0]), scroll => 1) };
+ $choices = [ sort { $a->name cmp $b->name } @$choices ];
+ my @choices = interactive_list_(N("Please choose"), P("The following package is needed:", "One of the following packages is needed:", scalar(@$choices)),
+ [ map { urpm_name($_) } @$choices ], $callback);
+ $choices->[$choices[0]];
+}
+
+sub toggle_nodes {
+ my ($widget, $model, $set_state, $old_state, @nodes) = @_;
+ @nodes = grep { exists $pkgs->{$_} } @nodes
+ or return;
+ #- avoid selecting too many packages at once
+ return if !$dont_show_selections && @nodes > 2000;
+ my $new_state = !$pkgs->{$nodes[0]}{selected};
+
+ my @nodes_with_deps;
+ my $deps_msg = sub {
+ return 1 if $dont_show_selections;
+ my ($title, $msg, $nodes, $nodes_with_deps) = @_;
+ my @deps = sort { $a cmp $b } difference2($nodes_with_deps, $nodes);
+ @deps > 0 or return 1;
+ deps_msg_again:
+ my $results = interactive_msg(
+ $title, $msg . urpm::select::translate_why_removed($urpm, $urpm->{state}, @deps),
+ yesno => [ N("Cancel"), N("More info"), N("Ok") ],
+ scroll => 1,
+ );
+ if ($results eq
+ #-PO: Keep it short, this is gonna be on a button
+ N("More info")) {
+ interactive_packtable(
+ N("Information on packages"),
+ $::main_window,
+ undef,
+ [ map { my $pkg = $_;
+ [ gtknew('HBox', children_tight => [ gtkset_selectable(gtknew('Label', text => $pkg), 1) ]),
+ gtknew('Button', text => N("More information on package..."),
+ clicked => sub {
+ interactive_msg(N("More information on package..."), get_info($pkg), scroll => 1);
+ }) ] } @deps ],
+ [ gtknew('Button', text => N("Ok"),
+ clicked => sub { Gtk2->main_quit }) ]
+ );
+ goto deps_msg_again;
+ } else {
+ return $results eq N("Ok");
+ }
+ }; # deps_msg
+
+ if (member($old_state, qw(to_remove installed))) { # remove pacckages
+ if ($new_state) {
+ my @remove;
+ slow_func($widget, sub { @remove = closure_removal(@nodes) });
+ @nodes_with_deps = grep { !$pkgs->{$_}{selected} && !/^basesystem/ } @remove;
+ $deps_msg->(N("Some additional packages need to be removed"),
+ formatAlaTeX(N("Because of their dependencies, the following package(s) also need to be\nremoved:")) . "\n\n",
+ \@nodes, \@nodes_with_deps) or @nodes_with_deps = ();
+ my @impossible_to_remove;
+ foreach (grep { exists $pkgs->{$_}{base} } @remove) {
+ ${$pkgs->{$_}{base}} == 1 ? push @impossible_to_remove, $_ : ${$pkgs->{$_}{base}}--;
+ }
+ @impossible_to_remove and interactive_msg(N("Some packages can't be removed"),
+ N("Removing these packages would break your system, sorry:\n\n") .
+ formatlistpkg(@impossible_to_remove));
+ @nodes_with_deps = difference2(\@nodes_with_deps, \@impossible_to_remove);
+ } else {
+ slow_func($widget,
+ sub { @nodes_with_deps = grep { intersection(\@nodes, [ closure_removal($_) ]) }
+ grep { $pkgs->{$_}{selected} && !member($_, @nodes) } keys %$pkgs });
+ push @nodes_with_deps, @nodes;
+ $deps_msg->(N("Some packages can't be removed"),
+ N("Because of their dependencies, the following package(s) must be\nunselected now:\n\n"),
+ \@nodes, \@nodes_with_deps) or @nodes_with_deps = ();
+ $pkgs->{$_}{base} && ${$pkgs->{$_}{base}}++ foreach @nodes_with_deps;
+ }
+ } else {
+ if ($new_state) {
+ if (@nodes > 1) {
+ #- unselect i18n packages of which locales is not already present (happens when user clicks on KDE group)
+ my @bad_i18n_pkgs;
+ foreach my $sel (@nodes) {
+ foreach ($pkgs->{$sel}{pkg}->requires_nosense) {
+ /locales-([^-]+)/ or next;
+ $sel =~ /-$1[-_]/ && !is_locale_available($_) and push @bad_i18n_pkgs, $sel;
+ }
+ }
+ @nodes = difference2(\@nodes, \@bad_i18n_pkgs);
+ }
+ my @requested;
+ slow_func(
+ $widget,
+ sub {
+ @requested = $urpm->resolve_requested(
+ $db, $urpm->{state},
+ { map { $pkgs->{$_}{pkg}->id => 1 } @nodes },
+ callback_choices => \&callback_choices,
+ );
+ },
+ );
+ @nodes_with_deps = map { urpm_name($_) } @requested;
+ if (!$deps_msg->(N("Additional packages needed"),
+ N("To satisfy dependencies, the following package(s) also need\nto be installed:\n\n"),
+ \@nodes, \@nodes_with_deps)) {
+ @nodes_with_deps = ();
+ $urpm->disable_selected($db, $urpm->{state}, @requested);
+ goto packages_selection_ok;
+ }
+
+ if (my @cant = sort(difference2(\@nodes, \@nodes_with_deps))) {
+ my @ask_unselect = urpm::select::unselected_packages($urpm, $urpm->{state});
+ my @reasons = map {
+ my $cant = $_;
+ my $unsel = find { $_ eq $cant } @ask_unselect;
+ $unsel
+ ? join("\n", urpm::select::translate_why_unselected($urpm, $urpm->{state}, $unsel))
+ : ($pkgs->{$_}{pkg}->flag_skip ? N("%s (belongs to the skip list)", $cant) : $cant);
+ } @cant;
+ my $count = @reasons;
+ interactive_msg(
+ P("One package cannot be installed", "Some packages can't be installed", $count),
+ P("Sorry, the following package cannot be selected:\n\n%s", "Sorry, the following packages can't be selected:\n\n%s", $count, join("\n", @reasons)),
+ scroll => 1,
+ );
+ foreach (@cant) {
+ $pkgs->{$_}{pkg}->set_flag_requested(0);
+ $pkgs->{$_}{pkg}->set_flag_required(0);
+ }
+ }
+ packages_selection_ok:
+ } else {
+ my @unrequested;
+ slow_func($widget,
+ sub { @unrequested = $urpm->disable_selected($db, $urpm->{state},
+ map { $pkgs->{$_}{pkg} } @nodes) });
+ @nodes_with_deps = map { urpm_name($_) } @unrequested;
+ if (!$deps_msg->(N("Some packages need to be removed"),
+ N("Because of their dependencies, the following package(s) must be\nunselected now:\n\n"),
+ \@nodes, \@nodes_with_deps)) {
+ @nodes_with_deps = ();
+ $urpm->resolve_requested($db, $urpm->{state}, { map { $_->id => 1 } @unrequested });
+ goto packages_unselection_ok;
+ }
+ packages_unselection_ok:
+ }
+ }
+
+ foreach (@nodes_with_deps) {
+ #- some deps may exist on some packages which aren't listed because
+ #- not upgradable (older than what currently installed)
+ exists $pkgs->{$_} or next;
+ if (!$pkgs->{$_}{pkg}) { #- can't be removed # FIXME; what about next packages in the loop?
+ $pkgs->{$_}{selected} = 0;
+ log::explanations("can't be removed: $_");
+ } else {
+ $pkgs->{$_}{selected} = $new_state;
+ }
+ $set_state->($_, node_state($_), $model);
+ $pkgs->{$_}{pkg}
+ and $size_selected += $pkgs->{$_}{pkg}->size * ($new_state ? 1 : -1);
+ }
+}
+
+sub do_action {
+ my ($options, $callback_action, $info) = @_;
+ require urpm::sys;
+ if (!urpm::sys::check_fs_writable()) {
+ $urpm->{fatal}(1, N("Error: %s appears to be mounted read-only.", $urpm::sys::mountpoint));
+ return;
+ }
+ if (!int(grep { $pkgs->{$_}{selected} } keys %$pkgs)) {
+ interactive_msg(N("You need to select some packages first."), N("You need to select some packages first."));
+ return;
+ }
+ my $size_added = sum(map { if_($_->flag_selected && !$_->flag_installed, $_->size) } @{$urpm->{depslist}});
+ if ($MODE eq 'install' && $size_free - $size_added/1024 < 50*1024) {
+ interactive_msg(N("Too many packages are selected"),
+ N("Warning: it seems that you are attempting to add so much
+packages that your filesystem may run out of free diskspace,
+during or after package installation ; this is particularly
+dangerous and should be considered with care.
+
+Do you really want to install all the selected packages?"), yesno => 1)
+ or return;
+ }
+ if (!$callback_action->($urpm, $pkgs)) {
+ $force_rebuild = 1;
+ pkgs_provider({ skip_updating_mu => 1 }, $options->{tree_mode});
+ reset_search();
+ $size_selected = 0;
+ (undef, $size_free) = MDK::Common::System::df('/usr');
+ $options->{rebuild_tree}->();
+ gtktext_insert($info, '');
+ }
+}
+
+
+sub ctreefy {
+ join('|', map { translate($_) } split m|/|, $_[0]);
+}
+
+sub build_tree {
+ my ($tree, $tree_model, $elems, $options, $force_rebuild, $compssUsers, $add_node, $flat, $mode) = @_;
+ my $old_mode if 0;
+ $mode = $options->{rmodes}{$mode} || $mode;
+ return if $old_mode eq $mode && !$force_rebuild;
+ $old_mode = $mode;
+ undef $force_rebuild;
+ my @elems;
+ my $wait; $wait = statusbar_msg(N("Please wait, listing packages...")) if $MODE ne 'update';
+ gtkflush();
+ if ($mode eq 'mandrake_choices') {
+ foreach my $pkg (keys %$pkgs) {
+ my ($name) = split_fullname($pkg);
+ push @elems, [ $pkg, $_ ] foreach @{$compssUsers->{$name}};
+ }
+ } else {
+ my @keys = keys %$pkgs;
+ if (member($mode, qw(all_updates security bugfix normal))) {
+ @keys = grep {
+ my ($name) = split_fullname($_);
+ member($descriptions->{$name}{importance}, @$mandrakeupdate_wanted_categories)
+ || ! $descriptions->{$name}{importance};
+ } @keys;
+ if (@keys == 0) {
+ $add_node->('', N("(none)"), { nochild => 1 });
+ my $explanation_only_once if 0;
+ $explanation_only_once or interactive_msg(N("No update"),
+ N("The list of updates is empty. This means that either there is
+no available update for the packages installed on your computer,
+or you already installed all of them."));
+ $explanation_only_once = 1;
+ }
+ }
+ @elems = map { [ $_, !$flat && ctreefy($pkgs->{$_}{pkg}->group) ] } @keys;
+ }
+ my %sortmethods = (
+ by_size => sub { sort { $pkgs->{$b->[0]}{pkg}->size <=> $pkgs->{$a->[0]}{pkg}->size } @_ },
+ by_selection => sub { sort { $pkgs->{$b->[0]}{selected} <=> $pkgs->{$a->[0]}{selected}
+ || uc($a->[0]) cmp uc($b->[0]) } @_ },
+ by_leaves => sub {
+ my $pkgs_times = 'rpm -q --qf "%{name}-%{version}-%{release} %{installtime}\n" `urpmi_rpm-find-leaves`';
+ sort { $b->[1] <=> $a->[1] } grep { exists $pkgs->{$_->[0]} } map { [ split ] } run_rpm($pkgs_times);
+ },
+ flat => sub { no locale; sort { uc($a->[0]) cmp uc($b->[0]) } @_ },
+ by_medium => sub { sort { $a->[2] <=> $b->[2] || uc($a->[0]) cmp uc($b->[0]) } @_ },
+ );
+ if ($flat) {
+ $add_node->($_->[0], '') foreach $sortmethods{$mode || 'flat'}->(@elems);
+ } else {
+ if (0 && $MODE eq 'update') {
+ $add_node->($_->[0], N("All")) foreach $sortmethods{flat}->(@elems);
+ $tree->expand_row($tree_model->get_path($tree_model->get_iter_first), 0);
+ } elsif ($mode eq 'by_source') {
+ $add_node->($_->[0], $_->[1]) foreach $sortmethods{by_medium}->(map {
+ my $m = pkg2medium($pkgs->{$_->[0]}{pkg}, $urpm); [ $_->[0], $m->{name}, $m->{priority} ];
+ } @elems);
+ } elsif ($mode eq 'by_presence') {
+ $add_node->(
+ $_->[0], $pkgs->{$_->[0]}{pkg}->flag_installed && !$pkgs->{$_->[0]}{pkg}->flag_skip
+ ? N("Upgradable") : N("Addable")
+ ) foreach $sortmethods{flat}->(@elems);
+ } else {
+ #- we populate all the groups tree at first
+ %$elems = ();
+ # better loop on packages, create groups tree and push packages in the proper place:
+ foreach my $pkg (@elems) {
+ my $grp = $pkg->[1];
+ $options->{add_parent}->($grp);
+ $elems->{$grp} ||= [];
+ push @{$elems->{$grp}}, $pkg;
+ }
+ }
+ }
+ statusbar_msg_remove($wait) if defined $wait;
+}
+
+sub get_info {
+ my ($key, $widget) = @_;
+ #- the package information hasn't been loaded. Instead of rescanning the media, just give up.
+ exists $pkgs->{$key} or return [ [ N("Description not available for this package\n") ] ];
+ exists $pkgs->{$key}{description} && exists $pkgs->{$key}{files}
+ or slow_func($widget, sub { extract_header($pkgs->{$key}, $urpm) });
+ my $s;
+ eval { $s = format_pkg_simplifiedinfo($pkgs, $key, $urpm, $descriptions) };
+ if (my $err = $@) {
+ $s = N("A fatal error occurred: %s.", $err);
+ }
+ $s;
+}
+
1;
diff --git a/rpmdrake b/rpmdrake
index e63e728c..00e47821 100755
--- a/rpmdrake
+++ b/rpmdrake
@@ -56,13 +56,6 @@ sub wait_msg_with_banner { push @_, banner => 1 if $::isEmbedded && !$treeview_d
warn_about_user_mode();
-my $dont_show_selections = $> ? 1 : 0;
-
-
-sub ctreefy {
- join('|', map { translate($_) } split m|/|, $_[0]);
-}
-
my $db = open_db();
sub do_search($$$$$$$) {
@@ -190,438 +183,29 @@ sub new {
package main;
-sub format_pkg_simplifiedinfo {
- my ($pkgs, $key, $urpm, $descriptions) = @_;
- my ($name, $_version) = split_fullname($key);
- my $medium = pkg2medium($pkgs->{$key}{pkg}, $urpm)->{name};
- my $update_descr = $pkgs->{$key}{pkg}->flag_upgrade && $descriptions->{$name}{pre} && $descriptions->{$name}{medium} eq $medium;
- my $s = ugtk2::markup_to_TextView_format(join("\n", format_header($name . ' - ' . $pkgs->{$key}{summary}) .
- # workaround gtk+ bug where GtkTextView wronly limit embedded widget size to bigger line's width (#25533):
- "\x{200b} \x{feff}" . ' ' x 120,
- if_($update_descr, # is it an update?
- format_field(N("Importance: ")) . escape_text_for_TextView_markup_format($descriptions->{$name}{importance}),
- format_field(N("Reason for update: ")) . escape_text_for_TextView_markup_format(rpm_description($descriptions->{$name}{pre})),
- ),
- '')); # extra empty line
- if ($update_descr) {
- push @$s, [ my $link = gtkshow(Gtk2::LinkButton->new($descriptions->{$name}{URL}, N("Security advisory"))) ];
- $link->set_uri_hook(sub {
- my (undef, $url) = @_;
- run_program::raw({ detach => 1 }, 'www-browser', $url);
- });
- }
-
- push @$s, @{ ugtk2::markup_to_TextView_format(join("\n",
- (escape_text_for_TextView_markup_format($pkgs->{$key}{description} || $descriptions->{$name}{description}) || '<i>' . N("No description") . '</i>')
- )) };
- push @$s, [ "\n" ];
- push @$s, [ gtkadd(gtkshow(my $exp = Gtk2::Expander->new(format_field(N("Files:")))),
- gtknew('TextView', text =>
- exists $pkgs->{$key}{files} ?
- ugtk2::markup_to_TextView_format('<tt>' . join("\n", map { "\x{200e}$_" } @{$pkgs->{$key}{files}}) . '</tt>') #- to highlight information
- : N("(Not available)"),
- )) ];
- $exp->set_use_markup(1);
- push @$s, [ "\n\n" ];
- push @$s, [ gtkadd(gtkshow(my $exp2 = Gtk2::Expander->new(format_field(N("Changelog:")))),
- gtknew('TextView', text => $pkgs->{$key}{changelog} || N("(Not available)"))
- ) ];
- $exp2->set_use_markup(1);
- $s;
-
-}
-
-sub format_pkg_info {
- my ($pkgs, $key, $urpm, $descriptions) = @_;
- my ($name, $version) = split_fullname($key);
- my @files = (
- format_field(N("Files:\n")),
- exists $pkgs->{$key}{files}
- ? '<tt>' . join("\n", map { "\x{200e}$_" } @{$pkgs->{$key}{files}}) . '</tt>' #- to highlight information
- : N("(Not available)"),
- );
- my @chglo = (format_field(N("Changelog:\n")), ($pkgs->{$key}{changelog} ? @{$pkgs->{$key}{changelog}} : N("(Not available)")));
- my @source_info = (
- $MODE eq 'remove' || !@$max_info_in_descr
- ? ()
- : (
- format_field(N("Medium: ")) . pkg2medium($pkgs->{$key}{pkg}, $urpm)->{name},
- format_field(N("Currently installed version: ")) . find_installed_version($pkgs->{$key}{pkg}),
- )
- );
- my @max_info = @$max_info_in_descr && $changelog_first ? (@chglo, @files) : (@files, '', @chglo);
- ugtk2::markup_to_TextView_format(join("\n", format_field(N("Name: ")) . $name,
- format_field(N("Version: ")) . $version,
- format_field(N("Architecture: ")) . $pkgs->{$key}{pkg}->arch,
- format_field(N("Size: ")) . N("%s KB", int($pkgs->{$key}{pkg}->size/1024)),
- if_(
- $MODE eq 'update',
- format_field(N("Importance: ")) . $descriptions->{$name}{importance}
- ),
- @source_info,
- '', # extra empty line
- format_field(N("Summary: ")) . $pkgs->{$key}{summary},
- '', # extra empty line
- if_(
- $MODE eq 'update',
- format_field(N("Reason for update: ")) . rpm_description($descriptions->{$name}{pre}),
- ),
- format_field(N("Description: ")), ($pkgs->{$key}{description} || $descriptions->{$name}{description} || N("No description")),
- @max_info,
- ));
-}
sub run_treeview_dialog {
my ($callback_action) = @_;
- my ($urpm, $pkgs, $descriptions);
- my (%filter_methods, $force_displaying_group, @initial_selection, $initial_selection_done);
- my $switch_pkg_list_mode = sub {
- my ($mode) = @_;
- return if !$mode;
- return if !$filter_methods{$mode};
- $force_displaying_group = 1;
- $filter_methods{$mode}->();
- };
- my $pkgs_provider = sub {
- my ($options, $mode) = @_;
- return if !$mode;
- my $h = &get_pkgs($urpm, $options); # was given (1, @_) for updates
- ($urpm, $descriptions) = @$h{qw(urpm update_descr)};
- %filter_methods = (
- all => sub { $pkgs = { map { %{$h->{$_}} } qw(installed installable updates) } },
- installed => sub { $pkgs = $h->{installed} },
- non_installed => sub { $pkgs = $h->{installable} },
- #mandrake_choices => sub { $pkgs = },
- all_updates => sub {
- my %pkgs = grep { my $p = $h->{installable}{$_}; $p->{pkg} && !$p->{selected} && $p->{pkg}->flag_installed && $p->{pkg}->flag_upgrade } keys %{$h->{installable}};
- $pkgs = {
- (map { $_ => $h->{updates}{$_} } keys %{$h->{updates}}),
- (map { $_ => $h->{installable}{$_} } keys %pkgs)
- };
- },
- #security => sub { $pkgs = },
- #normal => sub { $pkgs = }
- );
- if (!$initial_selection_done) {
- $filter_methods{all}->();
- @initial_selection = grep { $pkgs->{$_}{selected} } keys %$pkgs;
- $initial_selection_done = 1;
- }
- foreach my $importance (qw(bugfix security normal)) {
- $filter_methods{$importance} = sub {
- $pkgs = $h->{updates};
- $pkgs = { map { $_ => $pkgs->{$_} } grep {
- my ($name, $_version) = split_fullname($_);
- $descriptions->{$name}{importance} eq $importance } keys %$pkgs };
- };
- }
- $filter_methods{mandrake_choices} = $filter_methods{non_installed};
- $switch_pkg_list_mode->($mode);
- };
- my ($options, $size_selected, $compssUsers, $tree, $tree_model, $detail_list, $detail_list_model, %elems);
- my (undef, $size_free) = MDK::Common::System::df('/usr');
+ my ($options, $compssUsers, $tree, $tree_model, $detail_list, $detail_list_model, %elems);
+ (undef, $size_free) = MDK::Common::System::df('/usr');
$w = ugtk2->new(N("Software Management"));
$::main_window = $w->{real_window};
- my $is_locale_available = sub {
- any { $urpm->{depslist}[$_]->flag_selected } keys %{$urpm->{provides}{$_[0]} || {}} and return 1;
- my $found;
- $db->traverse_tag('name', [ $_ ], sub { $found ||= 1 });
- return $found;
- };
- my $callback_choices = sub {
- my (undef, undef, undef, $choices) = @_;
- foreach my $pkg (@$choices) {
- foreach ($pkg->requires_nosense) {
- /locales-/ or next;
- $is_locale_available->($_) and return $pkg;
- }
- }
- my $callback = sub { interactive_msg(N("More information on package..."), $options->{get_info}->($_[0]), scroll => 1) };
- $choices = [ sort { $a->name cmp $b->name } @$choices ];
- my @choices = interactive_list_(N("Please choose"), P("The following package is needed:", "One of the following packages is needed:", scalar(@$choices)),
- [ map { urpm_name($_) } @$choices ], $callback);
- $choices->[$choices[0]];
- };
-
- my $closure_removal = sub {
- $urpm->{state} = {};
- urpm::select::find_packages_to_remove($urpm, $urpm->{state}, \@_);
- };
- my $force_rebuild;
$options = {
- is_a_package => sub {
- my ($pkg) = @_;
- return exists $pkgs->{$pkg};
- },
- get_icon => \&get_icon,
- node_state => sub {
- my $pkg = $pkgs->{$_[0]};
- my $urpm_obj = $pkg->{pkg};
- $_[0] ? $pkg->{selected} ?
- ($urpm_obj->flag_installed ? ($urpm_obj->flag_upgrade ? 'to_install' : 'to_remove') : 'to_install')
- : ($urpm_obj->flag_installed ?
- ($urpm_obj->flag_upgrade ? 'to_update' : 'installed')
- : ($urpm_obj->flag_base ? '/usr/share/rpmdrake/icons/base.png' : 'uninstalled')) : 'XXX';
- }, #- checks $_[0] -> hack for partial tree displaying
- build_tree => sub {
- my ($add_node, $flat, $mode) = @_;
- my $old_mode if 0;
- $mode = $options->{rmodes}{$mode} || $mode;
- return if $old_mode eq $mode && !$force_rebuild;
- $old_mode = $mode;
- undef $force_rebuild;
- my @elems;
- my $wait; $wait = statusbar_msg(N("Please wait, listing packages...")) if $MODE ne 'update';
- gtkflush();
- if ($mode eq 'mandrake_choices') {
- foreach my $pkg (keys %$pkgs) {
- my ($name) = split_fullname($pkg);
- push @elems, [ $pkg, $_ ] foreach @{$compssUsers->{$name}};
- }
- } else {
- my @keys = keys %$pkgs;
- if (member($mode, qw(all_updates security bugfix normal))) {
- @keys = grep {
- my ($name) = split_fullname($_);
- member($descriptions->{$name}{importance}, @$mandrakeupdate_wanted_categories)
- || ! $descriptions->{$name}{importance};
- } @keys;
- if (@keys == 0) {
- $add_node->('', N("(none)"), { nochild => 1 });
- my $explanation_only_once if 0;
- $explanation_only_once or interactive_msg(N("No update"),
-N("The list of updates is empty. This means that either there is
-no available update for the packages installed on your computer,
-or you already installed all of them."));
- $explanation_only_once = 1;
- }
- }
- @elems = map { [ $_, !$flat && ctreefy($pkgs->{$_}{pkg}->group) ] } @keys;
- }
- my %sortmethods = (
- by_size => sub { sort { $pkgs->{$b->[0]}{pkg}->size <=> $pkgs->{$a->[0]}{pkg}->size } @_ },
- by_selection => sub { sort { $pkgs->{$b->[0]}{selected} <=> $pkgs->{$a->[0]}{selected}
- || uc($a->[0]) cmp uc($b->[0]) } @_ },
- by_leaves => sub {
- my $pkgs_times = 'rpm -q --qf "%{name}-%{version}-%{release} %{installtime}\n" `urpmi_rpm-find-leaves`';
- sort { $b->[1] <=> $a->[1] } grep { exists $pkgs->{$_->[0]} } map { [ split ] } run_rpm($pkgs_times);
- },
- flat => sub { no locale; sort { uc($a->[0]) cmp uc($b->[0]) } @_ },
- by_medium => sub { sort { $a->[2] <=> $b->[2] || uc($a->[0]) cmp uc($b->[0]) } @_ },
- );
- if ($flat) {
- $add_node->($_->[0], '') foreach $sortmethods{$mode || 'flat'}->(@elems);
- } else {
- if (0 && $MODE eq 'update') {
- $add_node->($_->[0], N("All")) foreach $sortmethods{flat}->(@elems);
- $tree->expand_row($tree_model->get_path($tree_model->get_iter_first), 0);
- } elsif ($mode eq 'by_source') {
- $add_node->($_->[0], $_->[1]) foreach $sortmethods{by_medium}->(map {
- my $m = pkg2medium($pkgs->{$_->[0]}{pkg}, $urpm); [ $_->[0], $m->{name}, $m->{priority} ];
- } @elems);
- } elsif ($mode eq 'by_presence') {
- $add_node->(
- $_->[0], $pkgs->{$_->[0]}{pkg}->flag_installed && !$pkgs->{$_->[0]}{pkg}->flag_skip
- ? N("Upgradable") : N("Addable")
- ) foreach $sortmethods{flat}->(@elems);
- } else {
- #- we populate all the groups tree at first
- %elems = ();
- # better loop on packages, create groups tree and push packages in the proper place:
- foreach my $pkg (@elems) {
- my $grp = $pkg->[1];
- $options->{add_parent}->($grp);
- $elems{$grp} ||= [];
- push @{$elems{$grp}}, $pkg;
- }
- }
- }
- statusbar_msg_remove($wait) if defined $wait;
- },
+ build_tree => sub { build_tree($tree, $tree_model, \%elems, $options, $force_rebuild, $compssUsers, @_) },
grep_unselected => sub { grep { exists $pkgs->{$_} && !$pkgs->{$_}{selected} } @_ },
partialsel_unsel => sub {
my ($unsel, $sel) = @_;
@$sel = grep { exists $pkgs->{$_} } @$sel;
@$unsel < @$sel;
},
- toggle_nodes => sub {
- my ($set_state, $old_state, @nodes) = @_;
- @nodes = grep { exists $pkgs->{$_} } @nodes
- or return;
- #- avoid selecting too many packages at once
- return if !$dont_show_selections && @nodes > 2000;
- my $new_state = !$pkgs->{$nodes[0]}{selected};
-
- my @nodes_with_deps;
- my $deps_msg = sub {
- return 1 if $dont_show_selections;
- my ($title, $msg, $nodes, $nodes_with_deps) = @_;
- my @deps = sort { $a cmp $b } difference2($nodes_with_deps, $nodes);
- @deps > 0 or return 1;
- deps_msg_again:
- my $results = interactive_msg(
- $title, $msg . urpm::select::translate_why_removed($urpm, $urpm->{state}, @deps),
- yesno => [ N("Cancel"), N("More info"), N("Ok") ],
- scroll => 1,
- );
- if ($results eq
- #-PO: Keep it short, this is gonna be on a button
- N("More info"))
- {
- interactive_packtable(
- N("Information on packages"),
- $w->{real_window},
- undef,
- [ map { my $pkg = $_;
- [ gtknew('HBox', children_tight => [ gtkset_selectable(gtknew('Label', text => $pkg), 1) ]),
- gtknew('Button', text => N("More information on package..."),
- clicked => sub {
- interactive_msg(N("More information on package..."), $options->{get_info}->($pkg), scroll => 1);
- }) ] } @deps ],
- [ gtknew('Button', text => N("Ok"),
- clicked => sub { Gtk2->main_quit }) ]
- );
- goto deps_msg_again;
- } else {
- return $results eq N("Ok");
- }
- }; # deps_msg
-
- if (member($old_state, qw(to_remove installed))) { # remove pacckages
- if ($new_state) {
- my @remove;
- slow_func($tree->window, sub { @remove = $closure_removal->(@nodes) });
- @nodes_with_deps = grep { !$pkgs->{$_}{selected} && !/^basesystem/ } @remove;
- $deps_msg->(N("Some additional packages need to be removed"),
- formatAlaTeX(N("Because of their dependencies, the following package(s) also need to be\nremoved:")) . "\n\n",
- \@nodes, \@nodes_with_deps) or @nodes_with_deps = ();
- my @impossible_to_remove;
- foreach (grep { exists $pkgs->{$_}{base} } @remove) {
- ${$pkgs->{$_}{base}} == 1 ? push @impossible_to_remove, $_ : ${$pkgs->{$_}{base}}--;
- }
- @impossible_to_remove and interactive_msg(N("Some packages can't be removed"),
- N("Removing these packages would break your system, sorry:\n\n") .
- formatlistpkg(@impossible_to_remove));
- @nodes_with_deps = difference2(\@nodes_with_deps, \@impossible_to_remove);
- } else {
- slow_func($tree->window,
- sub { @nodes_with_deps = grep { intersection(\@nodes, [ $closure_removal->($_) ]) }
- grep { $pkgs->{$_}{selected} && !member($_, @nodes) } keys %$pkgs });
- push @nodes_with_deps, @nodes;
- $deps_msg->(N("Some packages can't be removed"),
- N("Because of their dependencies, the following package(s) must be\nunselected now:\n\n"),
- \@nodes, \@nodes_with_deps) or @nodes_with_deps = ();
- $pkgs->{$_}{base} && ${$pkgs->{$_}{base}}++ foreach @nodes_with_deps;
- }
- } else {
- if ($new_state) {
- if (@nodes > 1) {
- #- unselect i18n packages of which locales is not already present (happens when user clicks on KDE group)
- my @bad_i18n_pkgs;
- foreach my $sel (@nodes) {
- foreach ($pkgs->{$sel}{pkg}->requires_nosense) {
- /locales-([^-]+)/ or next;
- $sel =~ /-$1[-_]/ && !$is_locale_available->($_) and push @bad_i18n_pkgs, $sel;
- }
- }
- @nodes = difference2(\@nodes, \@bad_i18n_pkgs);
- }
- my @requested;
- slow_func(
- $tree->window,
- sub {
- @requested = $urpm->resolve_requested(
- $db, $urpm->{state},
- { map { $pkgs->{$_}{pkg}->id => 1 } @nodes },
- callback_choices => $callback_choices,
- );
- },
- );
- @nodes_with_deps = map { urpm_name($_) } @requested;
- if (!$deps_msg->(N("Additional packages needed"),
- N("To satisfy dependencies, the following package(s) also need\nto be installed:\n\n"),
- \@nodes, \@nodes_with_deps))
- {
- @nodes_with_deps = ();
- $urpm->disable_selected($db, $urpm->{state}, @requested);
- goto packages_selection_ok;
- }
-
- if (my @cant = sort(difference2(\@nodes, \@nodes_with_deps))) {
- my @ask_unselect = urpm::select::unselected_packages($urpm, $urpm->{state});
- my @reasons = map {
- my $cant = $_;
- my $unsel = find { $_ eq $cant } @ask_unselect;
- $unsel
- ? join("\n", urpm::select::translate_why_unselected($urpm, $urpm->{state}, $unsel))
- : ($pkgs->{$_}{pkg}->flag_skip ? N("%s (belongs to the skip list)", $cant) : $cant);
- } @cant;
- my $count = @reasons;
- interactive_msg(
- P("One package cannot be installed", "Some packages can't be installed", $count),
- P("Sorry, the following package cannot be selected:\n\n%s", "Sorry, the following packages can't be selected:\n\n%s", $count, join("\n", @reasons)),
- scroll => 1,
- );
- foreach (@cant) {
- $pkgs->{$_}{pkg}->set_flag_requested(0);
- $pkgs->{$_}{pkg}->set_flag_required(0);
- }
- }
- packages_selection_ok:
- } else {
- my @unrequested;
- slow_func($tree->window,
- sub { @unrequested = $urpm->disable_selected($db, $urpm->{state},
- map { $pkgs->{$_}{pkg} } @nodes) });
- @nodes_with_deps = map { urpm_name($_) } @unrequested;
- if (!$deps_msg->(N("Some packages need to be removed"),
- N("Because of their dependencies, the following package(s) must be\nunselected now:\n\n"),
- \@nodes, \@nodes_with_deps))
- {
- @nodes_with_deps = ();
- $urpm->resolve_requested($db, $urpm->{state}, { map { $_->id => 1 } @unrequested });
- goto packages_unselection_ok;
- }
- packages_unselection_ok:
- }
- }
-
- foreach (@nodes_with_deps) {
- #- some deps may exist on some packages which aren't listed because
- #- not upgradable (older than what currently installed)
- exists $pkgs->{$_} or next;
- if (!$pkgs->{$_}{pkg}) { #- can't be removed # FIXME; what about next packages in the loop?
- $pkgs->{$_}{selected} = 0;
- log::explanations("can't be removed: $_");
- } else {
- $pkgs->{$_}{selected} = $new_state;
- }
- $set_state->($_, $options->{node_state}($_), $detail_list_model);
- $pkgs->{$_}{pkg}
- and $size_selected += $pkgs->{$_}{pkg}->size * ($new_state ? 1 : -1);
- }
- }, #- toggle_nodes
get_status => sub {
member($default_list_mode, qw(all non_installed))
? N("Selected: %s / Free disk space: %s", formatXiB($size_selected), formatXiB($size_free*1024))
: N("Selected size: %d MB", $size_selected/(1024*1024));
},
- get_info => sub {
- my ($key) = @_;
- #- the package information hasn't been loaded. Instead of rescanning the media, just give up.
- exists $pkgs->{$key} or return [ [ N("Description not available for this package\n") ] ];
- exists $pkgs->{$key}{description} && exists $pkgs->{$key}{files}
- or slow_func($tree->window, sub { extract_header($pkgs->{$key}, $urpm) });
- my $s;
- eval { $s = format_pkg_simplifiedinfo($pkgs, $key, $urpm, $descriptions) };
- if (my $err = $@) {
- $s = N("A fatal error occurred: %s.", $err);
- }
- $s;
- },
check_interactive_to_toggle => sub { 1 },
grep_allowed_to_toggle => sub { @_ },
rebuild_tree => sub {},
@@ -704,7 +288,6 @@ or you already installed all of them."));
bugfix => [ 'bugfix' ],
normal => [ 'normal' ],
);
- my $reset_search;
my $old_value;
my $cbox = gtksignal_connect(Gtk2::ComboBox->new_with_strings([ @modes{ 'all', if_($compssUsers, 'mandrake_choices'),
qw(installed non_installed all_updates security bugfix normal)
@@ -719,7 +302,7 @@ or you already installed all of them."));
@$mandrakeupdate_wanted_categories = @cat;
}
if (0) {
- $reset_search->();
+ reset_search();
$options->{rebuild_tree}->();
}
$options->{state}{flat} = 0; # was 1 only for the "All packages, alphabetical", "All packages, by size", "All packages, by selection state", and "Leaves only, sorted by install date"
@@ -729,8 +312,8 @@ or you already installed all of them."));
$options->{tree_submode} : $rmodes{$val};
$tree_mode->[0] = $options->{tree_mode};
$tree_flat->[0] = $options->{state}{flat};
- $reset_search->();
- slow_func($::main_window->window, sub { $switch_pkg_list_mode->($rmodes{$val}) });
+ reset_search();
+ slow_func($::main_window->window, sub { switch_pkg_list_mode($rmodes{$val}) });
$options->{rebuild_tree}->();
}
}
@@ -738,7 +321,6 @@ or you already installed all of them."));
my $default_radio = $options->{tree_mode} = $default_list_mode;
$cbox->set_text($modes{$default_radio});
- my $radio_by;
$options->{tree_submode} ||= $default_radio;
$options->{tree_subflat} ||= $options->{state}{flat};
@@ -769,48 +351,10 @@ or you already installed all of them."));
$info->set_left_margin(2);
$info->set_right_margin(15); #- workaround when right elevator of scrolled window appears
- my $find_entry;
- my $clear_button;
my $find_callback = sub {
$clear_button and $clear_button->set_sensitive(1);
do_search($find_entry, $tree, $tree_model, $options, $current_search_type, $urpm, $pkgs);
};
- $reset_search = sub {
- $clear_button and $clear_button->set_sensitive(0);
- $find_entry and $find_entry->set_text("");
- };
-
- my $do_action = sub {
- require urpm::sys;
- if (!urpm::sys::check_fs_writable()) {
- $urpm->{fatal}(1, N("Error: %s appears to be mounted read-only.", $urpm::sys::mountpoint));
- return;
- }
- if (!int(grep { $pkgs->{$_}{selected} } keys %$pkgs)) {
- interactive_msg(N("You need to select some packages first."), N("You need to select some packages first."));
- return;
- }
- my $size_added = sum(map { if_($_->flag_selected && !$_->flag_installed, $_->size) } @{$urpm->{depslist}});
- if ($MODE eq 'install' && $size_free - $size_added/1024 < 50*1024) {
- interactive_msg(N("Too many packages are selected"),
-N("Warning: it seems that you are attempting to add so much
-packages that your filesystem may run out of free diskspace,
-during or after package installation ; this is particularly
-dangerous and should be considered with care.
-
-Do you really want to install all the selected packages?"), yesno => 1)
- or return;
- }
- if (!$callback_action->($urpm, $pkgs)) {
- $force_rebuild = 1;
- $pkgs_provider->({ skip_updating_mu => 1 }, $options->{tree_mode});
- $reset_search->();
- $size_selected = 0;
- (undef, $size_free) = MDK::Common::System::df('/usr');
- $options->{rebuild_tree}->();
- gtktext_insert($info, '');
- }
- };
my $hpaned = gtknew('HPaned',
child1 => gtknew('ScrolledWindow', child => $tree, width => $typical_width*0.9) , resize1 => 0, shrink1 => 0,
@@ -832,8 +376,8 @@ Do you really want to install all the selected packages?"), yesno => 1)
update_sources_interactive($urpm, transient => $w->{real_window})
and do {
$force_rebuild = 1;
- $pkgs_provider->({ skip_updating_mu => 1 }, $options->{tree_mode});
- $reset_search->();
+ pkgs_provider({ skip_updating_mu => 1 }, $options->{tree_mode});
+ reset_search();
$size_selected = 0;
$options->{rebuild_tree}->();
};
@@ -847,7 +391,7 @@ Do you really want to install all the selected packages?"), yesno => 1)
);
}
$pkgs->{$_}{selected} = 0 foreach keys %$pkgs;
- $reset_search->();
+ reset_search();
$size_selected = 0;
$force_displaying_group = 1;
$tree->get_selection->signal_emit('changed');
@@ -855,9 +399,9 @@ Do you really want to install all the selected packages?"), yesno => 1)
[ N("/_File") . N("/Reload the _packages list"), undef, sub {
slow_func($::main_window->window, sub {
$force_rebuild = 1;
- $rmodes{$pkgs_provider->({ skip_updating_mu => 1 }, $options->{tree_mode})};
+ $rmodes{pkgs_provider({ skip_updating_mu => 1 }, $options->{tree_mode})};
});
- $reset_search->();
+ reset_search();
$size_selected = 0;
$options->{rebuild_tree}->();
}, undef, '<Item>' ],
@@ -925,7 +469,7 @@ Do you really want to install all the selected packages?"), yesno => 1)
gtksignal_connect(Gtk2::Button->new(but(N("Search"))), clicked => $find_callback),
gtksignal_connect(
$clear_button = Gtk2::Button->new(but(N("Clear"))),
- clicked => sub { $reset_search->() },
+ clicked => sub { reset_search() },
),
),
1, $hpaned,
@@ -946,7 +490,7 @@ Do you really want to install all the selected packages?"), yesno => 1)
),
0, my $action_button = gtksignal_connect(
Gtk2::Button->new(but_(N("Apply"))),
- clicked => sub { $do_action->() },
+ clicked => sub { do_action($options, $callback_action, $info) },
),
0, gtksignal_connect(
Gtk2::Button->new(but_(N("Quit"))),
@@ -978,7 +522,7 @@ Do you really want to install all the selected packages?"), yesno => 1)
$w->{rwindow}->show_all;
$w->{rwindow}->set_sensitive(0);
- $pkgs_provider->({}, $default_list_mode); # default mode
+ pkgs_provider({}, $default_list_mode); # default mode
if (@initial_selection) {
$options->{initial_selection} = \@initial_selection;
$pkgs->{$_}{selected} = 0 foreach @initial_selection;