Debian Codegraph @

Debconf/Element/Gnome/Progress.pm

raw
1 #!/usr/bin/perl
2
3 =head1 NAME
4
5 Debconf::Element::Gnome::Progress - progress bar widget
6
7 =cut
8
9 package Debconf::Element::Gnome::Progress;
10 use warnings;
11 use strict;
12 use Gtk3;
13 use utf8;
14 use Debconf::Encoding qw(to_Unicode);
15 use base qw(Debconf::Element::Gnome);
16
17 =head1 DESCRIPTION
18
19 This is a progress bar widget.
20
21 =cut
22
23 sub _fraction {
24 my $this=shift;
25
26 return (($this->progress_cur() - $this->progress_min()) / ($this->progress_max() - $this->progress_min()));
27 }
28
29 sub start {
30 my $this=shift;
31 my $description=to_Unicode($this->question->description);
32 my $frontend=$this->frontend;
33
34 $this->SUPER::init(@_);
35 $this->multiline(1);
36 $this->expand(1);
37
38 # Use the short description as the window title.
39 $frontend->title($description);
40
41 $this->widget(Gtk3::ProgressBar->new());
42 $this->widget->show;
43 # Make the progress bar a reasonable height by default.
44 $this->widget->set_text(' ');
45 $this->addwidget($this->widget);
46 $this->addhelp;
47 }
48
49 sub set {
50 my $this=shift;
51 my $value=shift;
52
53 $this->progress_cur($value);
54 $this->widget->set_fraction($this->_fraction);
55
56 # TODO: to support a cancelable progress bar, should return 0 here
57 # if the user hit cancel.
58 return 1;
59 }
60
61 sub info {
62 my $this=shift;
63 my $question=shift;
64
65 $this->widget->set_text(to_Unicode($question->description));
66
67 # TODO: to support a cancelable progress bar, should return 0 here
68 # if the user hit cancel.
69 return 1;
70 }
71
72 sub stop {
73 my $this=shift;
74 my $frontend=$this->frontend;
75
76 $frontend->title($frontend->requested_title);
77 }
78
79 1;