| 1 | package QWizard::Plugins::History; | ||
| 2 | |||
| 3 | our $VERSION = '3.15'; | ||
| 4 | require Exporter; | ||
| 5 | |||
| 6 | use strict; | ||
| 7 | |||
| 8 | our @ISA = qw(Exporter); | ||
| 9 | our @EXPORT = qw(get_history_widgets); | ||
| 10 | |||
| 11 | sub get_history_widgets { | ||
| 12 | return | ||
| 13 | ["Task History", | ||
| 14 | # { type => 'table', | ||
| 15 | # name => 'historyInfo', | ||
| 16 | # values => \&get_history_data | ||
| 17 | # } | ||
| 18 | { type => 'tree', | ||
| 19 | name => 'historyInfo', | ||
| 20 | root => 'history', | ||
| 21 | parent => \&get_history_parent, | ||
| 22 | children => \&get_history_children, | ||
| 23 | expand_all => 10, | ||
| 24 | default => sub { | ||
| 25 | # XX: doesn't quite work under Gtk2 at least. | ||
| 26 | my ($wiz) = @_; | ||
| 27 | my $res; | ||
| 28 | $wiz->foreach_primary($wiz->{'active'}, | ||
| 29 | sub { | ||
| 30 | my ($pdesc, $res, $wiz) = @_; | ||
| 31 | if (!$pdesc->{'done'}) { | ||
| 32 | $$res = $pdesc->{'name'}; | ||
| 33 | |||
| 34 | return 'STOP'; | ||
| 35 | } | ||
| 36 | }, \$res, $wiz); | ||
| 37 | return $res; | ||
| 38 | } | ||
| 39 | }, | ||
| 40 | ], | ||
| 41 | } | ||
| 42 | |||
| 43 | sub get_history_parent { | ||
| 44 | my ($wiz, $current) = @_; | ||
| 45 | my $parent; | ||
| 46 | return if ($current eq 'history'); | ||
| 47 | $wiz->foreach_primary($wiz->{'active'}, | ||
| 48 | sub { | ||
| 49 | my ($pdesc, $current, $parent) = @_; | ||
| 50 | if ($pdesc->{'name'} eq $$current) { | ||
| 51 | $$parent = $pdesc->{'parent'}{'name'} | ||
| 52 | if (exists($pdesc->{'parent'})); | ||
| 53 | return 'STOP'; | ||
| 54 | } | ||
| 55 | }, \$current, \$parent | ||
| 56 | ); | ||
| 57 | return 'history' if (!$parent); | ||
| 58 | return $parent; | ||
| 59 | } | ||
| 60 | |||
| 61 | sub get_history_children { | ||
| 62 | my ($wiz, $current) = @_; | ||
| 63 | my $parent; | ||
| 64 | my @ret; | ||
| 65 | $wiz->foreach_primary($wiz->{'active'}, | ||
| 66 | sub { | ||
| 67 | my ($pdesc, $current, $ret, $wiz) = @_; | ||
| 68 | # print "here: $$current\t$pdesc->{'name'}\n"; | ||
| 69 | if ($pdesc->{'name'} eq $$current || | ||
| 70 | ($$current eq 'history' && | ||
| 71 | $pdesc->{'name'} eq 'topcontainer')) { | ||
| 72 | map { | ||
| 73 | my $p = | ||
| 74 | $wiz->get_primary($_->{'name'}); | ||
| 75 | push @$ret, | ||
| 76 | { name => $_->{'name'}, | ||
| 77 | label => | ||
| 78 | $wiz->get_value($p->{'title'} || '') | ||
| 79 | }; | ||
| 80 | } @{$pdesc->{'children'}}; | ||
| 81 | |||
| 82 | # use Data::Dumper;; | ||
| 83 | # print Dumper($pdesc); | ||
| 84 | return 'STOP'; | ||
| 85 | } | ||
| 86 | }, \$current, \@ret, $wiz | ||
| 87 | ); | ||
| 88 | return \@ret; | ||
| 89 | } | ||
| 90 | |||
| 91 | sub get_history_data { | ||
| 92 | my ($wiz, $current, $q) = @_; | ||
| 93 | my @names; | ||
| 94 | my $first = 1; | ||
| 95 | my $linewidth = 1; | ||
| 96 | my $align = ""; | ||
| 97 | |||
| 98 | my $leftbar = "|"; | ||
| 99 | my $spacebar = " "; | ||
| 100 | my $lastbar = "-"; | ||
| 101 | my $currentbar = ">"; | ||
| 102 | |||
| 103 | $wiz->foreach_primary($wiz->{'active'}, | ||
| 104 | sub { | ||
| 105 | my ($countbars, $countspaces) = (0,0); | ||
| 106 | my $countall = 0; | ||
| 107 | my ($pdesc, $names, $wiz, $first) = @_; | ||
| 108 | my $x = $pdesc; | ||
| 109 | while(exists($x->{'parent'})) { | ||
| 110 | if ($x->{'parent'}{'qw_last_foreach'}) { | ||
| 111 | $countspaces++; | ||
| 112 | } else { | ||
| 113 | $countbars++; | ||
| 114 | } | ||
| 115 | $x = $x->{'parent'}; | ||
| 116 | } | ||
| 117 | my $p = $wiz->get_primary($pdesc->{'name'}); | ||
| 118 | my $name_str = $pdesc->{name} || ""; | ||
| 119 | my $doc_str = $p->{documentation} || ""; | ||
| 120 | my $title_str = $p->{title} || ""; | ||
| 121 | |||
| 122 | if ($p && $pdesc->{'done'}) { | ||
| 123 | push @$names, | ||
| 124 | [$spacebar x ($countspaces) . | ||
| 125 | $leftbar x ($countbars-1) . | ||
| 126 | (($pdesc->{qw_last_foreach}) ? $lastbar : $currentbar) . | ||
| 127 | $wiz->get_value($title_str)]; | ||
| 128 | } | ||
| 129 | if ($p && !$pdesc->{'done'}) { | ||
| 130 | my ($strs, $str); | ||
| 131 | ($str, $strs) = get_primary_history($wiz,$p); | ||
| 132 | map { | ||
| 133 | my $val = $wiz->get_value($_); | ||
| 134 | if ($$first) { | ||
| 135 | if ($pdesc->{'merge'}) { | ||
| 136 | $$first += $pdesc->{'merge'} - 1; | ||
| 137 | } | ||
| 138 | $val = "*** $val ***"; | ||
| 139 | $$first--; | ||
| 140 | } | ||
| 141 | push @$names, | ||
| 142 | [$spacebar x ($countspaces) . | ||
| 143 | $leftbar x ($countbars-1) . | ||
| 144 | (($pdesc->{qw_last_foreach}) ? $lastbar : $currentbar) . "$val"]; | ||
| 145 | } @$strs; | ||
| 146 | } | ||
| 147 | }, \@names, $wiz, \$first | ||
| 148 | ); | ||
| 149 | return [\@names]; | ||
| 150 | } | ||
| 151 | |||
| 152 | sub get_primary_history { | ||
| 153 | my ($wiz, $p) = @_; | ||
| 154 | my $str = $wiz->get_value($p->{'title'}); | ||
| 155 | my @results; | ||
| 156 | push @results, $str if (defined($str)); | ||
| 157 | if ($p->{'sub_modules'}) { | ||
| 158 | foreach my $i (@{$wiz->get_values($p->{'sub_modules'})}) { | ||
| 159 | my ($newstr, $newres) = | ||
| 160 | get_primary_history($wiz, $wiz->{'primaries'}{$i}); | ||
| 161 | $str .= "," . $newstr; | ||
| 162 | push @results, @$newres; | ||
| 163 | } | ||
| 164 | } | ||
| 165 | if ($p->{'sub_history'}) { | ||
| 166 | $str .= "," . join(",",@{$wiz->get_values($p->{'sub_history'})}); | ||
| 167 | push @results, @{$wiz->get_values($p->{'sub_history'})}; | ||
| 168 | } | ||
| 169 | return ($str, \@results); | ||
| 170 | } | ||
| 171 | |||
| 172 | 1; | ||
| 173 | |||
| 174 | ########################################################################### | ||
| 175 | |||
| 176 | =pod | ||
| 177 | |||
| 178 | =head1 NAME | ||
| 179 | |||
| 180 | QWizard::Plugins::History - Show a QWizard History Widget | ||
| 181 | |||
| 182 | =head1 SYNOPSIS | ||
| 183 | |||
| 184 | use QWizard::Plugins::History; | ||
| 185 | |||
| 186 | # add the history widget to the left side | ||
| 187 | $qw = new QWizard(leftside => [get_history_widgets()]); | ||
| 188 | |||
| 189 | # ... | ||
| 190 | $qw->magic('blah'); | ||
| 191 | |||
| 192 | =head1 DESCRIPTION | ||
| 193 | |||
| 194 | The history widget (best used in a sidebar) displays a list of | ||
| 195 | completed and future qwizard screen titles that are in the todo list | ||
| 196 | to finish. | ||
| 197 | |||
| 198 | =head1 AUTHOR | ||
| 199 | |||
| 200 | Wes Hardaker, hardaker@users.sourceforge.net | ||
| 201 | |||
| 202 | =head1 SEE ALSO | ||
| 203 | |||
| 204 | perl(1) | ||
| 205 | |||
| 206 | NetPolicy::module_utils(3) | ||
| 207 | |||
| 208 | http://net-policy.sourceforge.net/ | ||
| 209 | |||
| 210 | =cut | ||
| 211 | |||
| 212 | |||
| 213 |