aboutsummaryrefslogtreecommitdiffstats
path: root/Rpmdrake/gurpm.pm
blob: f3ece16ad75df43453afbf82f80f1acc8536c76a (plain)
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
package Rpmdrake::gurpm;
#*****************************************************************************
#
#  Copyright (c) 2002 Guillaume Cottenceau
#  Copyright (c) 2002-2007 Thierry Vignaud <tvignaud@mandriva.com>
#  Copyright (c) 2003, 2004, 2005 MandrakeSoft SA
#  Copyright (c) 2005-2007 Mandriva SA
#
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License version 2, as
#  published by the Free Software Foundation.
#
#  This program 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 General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
#*****************************************************************************
#
# $Id: gurpm.pm 255450 2009-04-03 16:00:16Z tv $

use strict;
use lib qw(/usr/lib/libDrakX);
use mygtk3 qw(gtknew);  #- do not import anything else, especially gtkadd() which conflicts with ugtk3 one
use ugtk3 qw(:all);
use base qw(ugtk3);
use Time::HiRes;
use feature 'state';


sub new {
    my ($self, $title, $initializing, %options) = @_;
    my $mainw = bless(ugtk3->new($title, %options, default_width => 600, width => 600), $self);
    $::main_window = $mainw->{real_window};
    $mainw->{label} = gtknew('Label', text => $initializing, alignment => [ 0.5, 0 ]);
    # size label's heigh to 2 lines in order to prevent dummy vertical resizing:
    my $context = $mainw->{label}->get_layout->get_context;
    my $metrics = $context->get_metrics(undef, $context->get_language);
    $mainw->{label}->set_size_request(-1, 2 * Pango->PANGO_PIXELS($metrics->get_ascent + $metrics->get_descent));

    $mainw->{progressbar} = gtknew('ProgressBar');
    gtkadd($mainw->{window}, $mainw->{vbox} = gtknew('VBox', spacing => 5, border_width => 6, children_tight => [
        $mainw->{label},
        $mainw->{progressbar}
    ]));
    $mainw->{rwindow}->set_position('center-on-parent');
    $mainw->{real_window}->show_all;
    select(undef, undef, undef, 0.1);  #- hackish :-(
    $mainw->SUPER::sync;
    $mainw;
}

sub label {
    my ($self, $label) = @_;
    $self->{label}->set($label);
    select(undef, undef, undef, 0.1);  #- hackish :-(
    $self->flush;
}

sub progress {
    my ($self, $fraction) = @_;
    state $time;
    $fraction = 0 if $fraction < 0;
    $fraction = 1 if 1 < $fraction;
    $self->{progressbar}->set_fraction($fraction);
    return if Time::HiRes::clock_gettime() - $time < 0.333;
    $time = Time::HiRes::clock_gettime();
    $self->flush;
}

sub DESTROY {
    my ($self) = @_;
    mygtk3::may_destroy($self);
    $self and $self->destroy;
    $self = undef;
    $self->{cancel} = undef;  #- in case we'll do another one later
}

sub validate_cancel {
    my ($self, $cancel_msg, $cancel_cb) = @_;
    if (!$self->{cancel}) {
        gtkpack__(
	    $self->{vbox},
	    $self->{hbox_cancel} = gtkpack__(
		gtknew('HButtonBox'),
		$self->{cancel} = gtknew('Button', text => $cancel_msg, clicked => \&$cancel_cb),
	    ),
	);
    }
    $self->{cancel}->set_sensitive(1);
    $self->{cancel}->show;
}

sub invalidate_cancel {
    my ($self) = @_;
    $self->{cancel} and $self->{cancel}->set_sensitive(0);
}

sub invalidate_cancel_forever {
    my ($self) = @_;
    $self->{hbox_cancel} or return;
    $self->{hbox_cancel}->destroy;
    # FIXME: temporary workaround that prevents
    # Gtk3::Label::set_text() set_text_internal() -> queue_resize() ->
    # size_allocate() call chain to mess up when ->shrink_topwindow()
    # has been called (#32613):
    #$self->shrink_topwindow;
}

1;