/usr/share/perl5/Gtk2/Ex/FormFactory/ExecFlow.pm is in libgtk2-ex-formfactory-perl 0.66-0ubuntu2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 | package Gtk2::Ex::FormFactory::ExecFlow;
use strict;
use base qw( Gtk2::Ex::FormFactory::Widget );
sub get_type {"execflow"}
sub get_add_columns { shift->{add_columns} }
sub get_path_by_id_href { shift->{path_by_id_href} }
sub set_add_columns { shift->{add_columns} = $_[1] }
sub set_path_by_id_href { shift->{path_by_id_href} = $_[1] }
sub new {
my $class = shift;
my %par = @_;
my ($add_columns) = $par{'add_columns'};
$add_columns ||= [];
my $self = $class->SUPER::new(@_);
$self->set_add_columns($add_columns);
return $self;
}
sub build_widget {
my $self = shift;
my $model = Gtk2::TreeStore->new(
"Glib::String", "Glib::String", "Glib::String",
("Glib::String") x @{$self->get_add_columns}
);
my $tree_view = Gtk2::TreeView->new_with_model($model);
for my $i ( 0..1+@{$self->get_add_columns} ) {
my $column = Gtk2::TreeViewColumn->new_with_attributes(
"col$i",
Gtk2::CellRendererText->new,
'text' => $i < 2 ? $i : $i + 1
);
$tree_view->append_column($column);
}
$tree_view->set_headers_visible(0);
$tree_view->set_rules_hint(1);
$self->set_gtk_widget($tree_view);
1;
}
sub empty_widget {
my $self = shift;
$self->get_gtk_widget->get_model->clear;
$self->set_path_by_id_href({});
1;
}
sub object_to_widget {
my $self = shift;
my $job = $self->get_object_value;
return unless $job;
$self->empty_widget;
$self->add_job_to_model($job, undef);
$self->get_gtk_widget->expand_all;
1;
}
sub add_job_to_model {
my $self = shift;
my ($job, $parent_iter) = @_;
my $model = $self->get_gtk_widget->get_model;
my $iter = $model->append($parent_iter);
$model->set($iter, 0 => $job->get_info);
$model->set($iter, 1 => $job->get_progress_stats);
$model->set($iter, 2 => $job->get_id);
my $i = 3;
foreach my $add_col ( @{$self->get_add_columns} ) {
my $method = "get_$add_col";
$model->set($iter, $i => $job->$method());
++$i;
}
my $path = $model->get_path($iter);
$self->get_path_by_id_href->{$job->get_id} = $path;
if ( $job->get_type eq 'group' ) {
foreach my $child_job ( @{$job->get_jobs} ) {
$self->add_job_to_model($child_job, $iter);
}
}
1;
}
sub update_job {
my $self = shift;
my ($job) = @_;
my $path = $self->get_path_by_id_href->{$job->get_id};
return if !$path;
my $model = $self->get_gtk_widget->get_model;
my $iter = $model->get_iter($path);
$model->set($iter, 0 => $job->get_info);
$model->set($iter, 1 => $job->get_progress_stats);
my $i = 3;
foreach my $add_col ( @{$self->get_add_columns} ) {
my $method = "get_$add_col";
$model->set($iter, $i => $job->$method());
++$i;
}
1;
}
sub add_job {
my $self = shift;
my ($job) = @_;
my $group = $job->get_group;
my $group_path = $self->get_path_by_id_href->{$group->get_id};
return $self->add_job_to_model($job) if !$group_path;
my $model = $self->get_gtk_widget->get_model;
my $iter = $model->get_iter($group_path);
$self->add_job_to_model($job, $iter);
$self->get_gtk_widget->expand_row($group_path, 0);
$self->get_gtk_widget->expand_row(
$self->get_path_by_id_href->{$job->get_id},
1
);
1;
}
sub remove_job {
my $self = shift;
my ($job) = @_;
$self->remove_job_with_id($job->get_id);
1;
}
sub remove_job_with_id {
my $self = shift;
my ($job_id) = @_;
my $path = $self->get_path_by_id_href->{$job_id};
my $model = $self->get_gtk_widget->get_model;
$model->remove($model->get_iter($path));
$self->rebuild_job_path_index;
1;
}
sub rebuild_job_path_index {
my $self = shift;
my %path_by_job_id;
my $model = $self->get_gtk_widget->get_model;
$model->foreach(sub{
#-- Storing the Gtk2::TreePath doesn't work here, weird
#-- stuff happens. So we store the string and turn it
#-- into a Gtk2::TreePath after the foreach iteration.
$path_by_job_id{$model->get($_[2],2)} = $_[1]->to_string;
return 0;
});
#-- Turn path strings into Gtk2::TreePath objects
foreach my $job_id ( sort {$a <=> $b} keys %path_by_job_id ) {
$path_by_job_id{$job_id} =
Gtk2::TreePath->new_from_string($path_by_job_id{$job_id});
}
$self->set_path_by_id_href(\%path_by_job_id);
1;
}
1;
__END__
=head1 NAME
Gtk2::Ex::FormFactory::ExecFlow - Display a Event::ExecFlow job plan
=head1 SYNOPSIS
Gtk2::Ex::FormFactory::ExecFlow->new (
...
Gtk2::Ex::FormFactory::Widget attributes
);
=head1 DESCRIPTION
This class implements a Event::ExecFlow job plan viewer in a
Gtk2::Ex::FormFactory framework using a Gtk2::TreeView to display
the hierarchical job structure.
Besides updating the whole TreeView by assigning a new Event::ExecFlow::Job
object to the widget it offers methods for updating single jobs
efficiently.
The value of the associated application object attribute is an
Event::ExecFlow::Job object.
=head1 OBJECT HIERARCHY
Gtk2::Ex::FormFactory::Intro
Gtk2::Ex::FormFactory::Widget
+--- Gtk2::Ex::FormFactory::ExecFlow
Gtk2::Ex::FormFactory::Layout
Gtk2::Ex::FormFactory::Rules
Gtk2::Ex::FormFactory::Context
Gtk2::Ex::FormFactory::Proxy
=head1 ATTRIBUTES
This module has no additional attributes over those derived
from Gtk2::Ex::FormFactory::Widget.
=back
For more attributes refer to L<Gtk2::Ex::FormFactory::Widget>.
=head1 METHODS
=over 4
=item $widget->B<add_job> ($job)
This adds B<$job> to the widget. If the job is part of a job
group the group must be added already to the widget.
=item $widget->B<update_job> ($job)
Updates the state of B<$job> in the TreeView.
=item $widget->B<remove_job> ($job)
Removes B<$job> from the TreeView.
=item $widget->B<remove_job_with_id> ($job_id)
Use this method to remove a job from the TreeView if you
just know it's ID and don't have a $job object at hand.
=back
=head1 AUTHORS
Jörn Reder <joern at zyn dot de>
=head1 COPYRIGHT AND LICENSE
Copyright 2004-2006 by Jörn Reder.
This library is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2.1 of the
License, or (at your option) any later version.
This library 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307
USA.
=cut
|