diff options
author | Matteo Pasotti <matteo@mageia.org> | 2013-01-11 01:26:26 +0000 |
---|---|---|
committer | Matteo Pasotti <matteo@mageia.org> | 2013-01-11 01:26:26 +0000 |
commit | 96eb75a0db4fd879415f21b2b38a2c2927e50d43 (patch) | |
tree | a67599d3452e4f2fd6c9e4a5e8ce4a3e12736b19 | |
parent | 2e0f9b70beecb7bdd27e74088368936cdb718c72 (diff) | |
download | manatools-96eb75a0db4fd879415f21b2b38a2c2927e50d43.tar manatools-96eb75a0db4fd879415f21b2b38a2c2927e50d43.tar.gz manatools-96eb75a0db4fd879415f21b2b38a2c2927e50d43.tar.bz2 manatools-96eb75a0db4fd879415f21b2b38a2c2927e50d43.tar.xz manatools-96eb75a0db4fd879415f21b2b38a2c2927e50d43.zip |
- gui.pm: rewritten set_node_state, set_leaf_state
- gui.pm: added subroutines group_tree, group_has_parent, group_parent
- formatting.pm: imported escape_text_for_TextView_markup_format from ugtk2
- rpmdragora: added tree_callback
-rw-r--r-- | AdminPanel/Rpmdragora/formatting.pm | 14 | ||||
-rw-r--r-- | AdminPanel/Rpmdragora/gui.pm | 78 | ||||
-rwxr-xr-x | modules/rpmdragora/rpmdragora | 51 |
3 files changed, 116 insertions, 27 deletions
diff --git a/AdminPanel/Rpmdragora/formatting.pm b/AdminPanel/Rpmdragora/formatting.pm index 3d650a4f..ccbdf0c8 100644 --- a/AdminPanel/Rpmdragora/formatting.pm +++ b/AdminPanel/Rpmdragora/formatting.pm @@ -29,6 +29,7 @@ use utf8; use POSIX qw(strftime); use AdminPanel::rpmdragora; use lib qw(/usr/lib/libDrakX); +use MDK::Common::Various; # included for internal_error subroutine use common; #use ugtk2 qw(escape_text_for_TextView_markup_format); @@ -54,6 +55,19 @@ our @EXPORT = qw( ); +sub escape_text_for_TextView_markup_format { + my ($str) = @_; + my %rules = ('&' => '&', + '<' => '<', + '>' => '>', + ); + eval { $str =~ s!([&<>])!$rules{$1}!g }; #^(&(amp|lt|gt);)!!) { + if (my $err = $@) { + internal_error("$err\n$str"); + } + $str; +} + # from rpmtools, #37482: sub ensure_utf8 { if (utf8::is_utf8($_[0])) { diff --git a/AdminPanel/Rpmdragora/gui.pm b/AdminPanel/Rpmdragora/gui.pm index 2ab7d78b..b5f03001 100644 --- a/AdminPanel/Rpmdragora/gui.pm +++ b/AdminPanel/Rpmdragora/gui.pm @@ -65,6 +65,9 @@ our @EXPORT = qw( do_action get_info get_summary + group_has_parent + group_parent + groups_tree is_locale_available node_state pkgs_provider @@ -404,11 +407,15 @@ my ($common, $w, %wtree, %ptree, %pix); sub set_node_state { my ($iter, $state, $model) = @_; return if $state eq 'XXX' || !$state; - $pix{$state} ||= gtkcreate_pixbuf('state_' . $state); - $model->set($iter, $pkg_columns{state_icon} => $pix{$state}); - $model->set($iter, $pkg_columns{state} => $state); - $model->set($iter, $pkg_columns{selected} => to_bool(member($state, qw(base installed to_install)))); #$pkg->{selected})); - $model->set($iter, $pkg_columns{selectable} => to_bool($state ne 'base')); + #$pix{$state} ||= gtkcreate_pixbuf('state_' . $state); + #$model->set($iter, $pkg_columns{state_icon} => $pix{$state}); + #$model->set($iter, $pkg_columns{state} => $state); + #$model->set($iter, $pkg_columns{selected} => to_bool(member($state, qw(base installed to_install)))); #$pkg->{selected})); + #$model->set($iter, $pkg_columns{selectable} => to_bool($state ne 'base')); + $iter->addCell('',"/home/matteo/workspace/AdminPanel/trunk/modules/rpmdragora/icons/state_$state.png"); + $iter->addCell($state,''); + $iter->addCell("".to_bool(member($state, qw(base installed to_install))),''); + $iter->addCell("".to_bool($state ne 'base'),''); } sub set_leaf_state { @@ -460,14 +467,24 @@ sub add_node { my $iter; if (is_a_package($leaf)) { my ($name, $version, $release, $arch) = split_fullname($leaf); - $iter = $w->{detail_list_model}->append_set([ $pkg_columns{text} => $leaf, - $pkg_columns{short_name} => format_name_n_summary($name, get_summary($leaf)), - $pkg_columns{version} => $version, - $pkg_columns{release} => $release, - $pkg_columns{arch} => $arch, - ]); - set_node_state($iter, $state, $w->{detail_list_model}); - $ptree{$leaf} = [ $iter ]; + #OLD $iter = $w->{detail_list_model}->append_set([ $pkg_columns{text} => $leaf, + # $pkg_columns{short_name} => format_name_n_summary($name, get_summary($leaf)), + # $pkg_columns{version} => $version, + # $pkg_columns{release} => $release, + # $pkg_columns{arch} => $arch, + # ]); + $name = "" if(!defined($name)); + $version = "" if(!defined($version)); + $release = "" if(!defined($release)); + $arch = "" if(!defined($arch)); + my $newTableItem = new yui::YTableItem($leaf, + format_name_n_summary($name, get_summary($leaf)), + $version, + $release, + $arch); + $w->{detail_list}->addItem($newTableItem); + set_node_state($newTableItem, $state, $w->{detail_list_model}); + $ptree{$leaf} = [ $newTableItem->label() ]; } else { $iter = $w->{tree_model}->append_set(add_parent($w->{tree},$root, $state), [ $grp_columns{label} => $leaf ]); push @{$wtree{$leaf}}, $iter; @@ -563,7 +580,9 @@ sub ask_browse_tree_given_widgets_for_rpmdragora { my (@nodes) = @_; $w->{detail_list}->deleteAllItems(); #$w->{detail_list}->scroll_to_point(0, 0); - add_node($_->[0], $_->[1], $_->[2]) foreach @nodes; + foreach(@nodes){ + add_node($_->[0], $_->[1], $_->[2]); + } update_size($common); }; @@ -1040,7 +1059,9 @@ or you already installed all of them.")); add_node($tree->currentItem()->label(), '') foreach $sortmethods{$::mode->[0] || 'flat'}->(@elems); } else { if (0 && $MODE eq 'update') { - add_node($tree->currentItem()->label(), $_->[0], N("All")) foreach $sortmethods{flat}->(@elems); + foreach ($sortmethods{flat}->(@elems)){ + add_node($tree->currentItem()->label(), $_->[0], N("All")) + } $tree->expand_row($tree_model->get_path($tree_model->get_iter_first), 0); } elsif ($::mode->[0] eq 'by_source') { _build_tree($tree, $elems, $sortmethods{by_medium}->(map { @@ -1055,6 +1076,7 @@ or you already installed all of them.")); } $sortmethods{flat}->(@elems)); } else { _build_tree($tree, $elems, @elems); + # INFO: $elems contains references to the packages of the group, see _build_tree } } statusbar_msg_remove($wait) if defined $wait; @@ -1081,4 +1103,30 @@ sub run_help_callback { run_program::raw({ detach => 1, as_user => 1 }, 'www-browser', $url); } +sub groups_tree { + return %groups_tree; +} + +sub group_has_parent { + my ($group) = shift; + return (defined($groups_tree{$group}{parent})); +} + +sub group_parent { + my ($group) = shift; + # if group is a parent itself return it + # who use group_parent have to take care of the comparison + # between a group and its parent + # e.g. group System has groups_tree{'System'}{parent}->label() = 'System' + return $groups_tree{$group}{parent} if(group_has_parent($group)); + for my $sup (keys %groups_tree){ + for my $item(keys %{$groups_tree{$sup}{children}}){ + if($item eq $group){ + return $groups_tree{$sup}{parent}; + } + } + } + return undef; +} + 1; diff --git a/modules/rpmdragora/rpmdragora b/modules/rpmdragora/rpmdragora index d8225e42..c9278029 100755 --- a/modules/rpmdragora/rpmdragora +++ b/modules/rpmdragora/rpmdragora @@ -95,6 +95,40 @@ sub filterbox_callback { $options->{rebuild_tree}->(); } } +my $current_group = -1; +sub tree_callback { + my ($selection, $options) = @_; + #OLD my ($model, $iter) = $tree->currentItem(); + #OLD return if !$iter; + #state $current_group; + #OLD my $new_group = $model->get_path_str($iter); + #my $new_group = $selection->index(); + #$current_group = -1 if(!defined($current_group)); + #return if $current_group eq $new_group && !$force_displaying_group; + undef $force_displaying_group; + #$current_group = $new_group; + #OLD $model && $iter or return; + $selection or return; + #OLD my $group = $model->get($iter, 0); + my $group = $selection->label(); + # documentation reference for ->parent() method + # http://doc.opensuse.org/projects/libyui/HEAD/classYItem.html#af78069741ce6b64f7512bc08b5bc857b + # WARNING: it seems that parent method don't return 0 if there is no parent :-( + # WARNING: it seems that parent method actually don't work at all :-/ + #DO NOT WORK my $parent = $selection->parent(); + my $parent = group_parent($group); + while (defined($parent)) { + last if($parent->label() eq $group); + $group = join('|', $parent->label(), $group); + $parent = group_parent(); + } + if(!$selection->hasChildren()){ + #$detail_list->window->freeze_updates; + $options->{add_nodes}->(@{$elems{$group}}); + #$detail_list->window->thaw_updates if $detail_list->window; + } + return; +} sub do_search($$$$$$$) { my ($find_entry, $tree, $tree_model, $options, $current_search_type, $urpm, $pkgs) = @_; @@ -327,6 +361,7 @@ sub run_treeview_dialog { # Tree for groups $tree = $factory->createTree($hbox_middle, ""); $tree->setWeight(0,20); + $tree->setNotify(1); #OLD $tree->get_selection->set_mode('browse'); #OLD $tree->append_column(Gtk2::TreeViewColumn->new_with_attributes(undef, Gtk2::MDV::CellRendererPixWithLabel->new, 'pixbuf' => $grp_columns{icon}, label => $grp_columns{label})); @@ -957,17 +992,9 @@ sub run_treeview_dialog { } elsif ($widget == $filter_box) { filterbox_callback($filter_box->selectedItem()->label(), \%$options, \%rfilters); - #state $oldval; - #my $val = $filter_box->selectedItem()->label(); - #return if $val eq $oldval; # workarounding gtk+ sending us sometimes twice events - #$oldval = $val; - #$val = $rfilters{$val}; - #if ($filter->[0] ne $val) { - # $filter->[0] = $val; - # reset_search(); - # slow_func($::main_window, sub { switch_pkg_list_mode($default_list_mode) }); - # $options->{rebuild_tree}->(); - #} + } + elsif ($widget == $tree) { + tree_callback($tree->currentItem(),\%$options); } elsif ($widget == $file_menu && $mnuItemUpdateMedia) { update_sources_interactive($urpm, transient => $my_win) @@ -1001,7 +1028,7 @@ sub run_treeview_dialog { else { ### any other events if ($event->item()) { - #print $event->item()->label() . "\n"; + # print $event->item()->label() . "\n"; # items if ($event->item()->label() eq $mnuItemExit->label()) { #menu File->Quit |