| 1 | # show final status of a job as a MessageUntilKey or something | ||
| 2 | |||
| 3 | |||
| 4 | |||
| 5 | |||
| 6 | # Copyright 2008, 2009, 2010, 2011, 2012 Kevin Ryde | ||
| 7 | |||
| 8 | # This file is part of Chart. | ||
| 9 | # | ||
| 10 | # Chart is free software; you can redistribute it and/or modify it under the | ||
| 11 | # terms of the GNU General Public License as published by the Free Software | ||
| 12 | # Foundation; either version 3, or (at your option) any later version. | ||
| 13 | # | ||
| 14 | # Chart is distributed in the hope that it will be useful, but WITHOUT ANY | ||
| 15 | # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
| 16 | # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | ||
| 17 | # details. | ||
| 18 | # | ||
| 19 | # You should have received a copy of the GNU General Public License along | ||
| 20 | # with Chart. If not, see <http://www.gnu.org/licenses/>. | ||
| 21 | |||
| 22 | package App::Chart::Gtk2::JobStatusbarMessage; | ||
| 23 | 1 | ▶ | use 5.008; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 24 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 25 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 26 | 0 | ▶ | use Gtk2; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 27 | |||
| 28 | # uncomment this to run the ### lines | ||
| 29 | #use Smart::Comments; | ||
| 30 | |||
| 31 | use App::Chart::Glib::Ex::MoreUtils; | ||
| 32 | use Gtk2::Ex::Statusbar::Message; | ||
| 33 | use App::Chart::Gtk2::Job; | ||
| 34 | |||
| 35 | use Glib::Object::Subclass | ||
| 36 | 'Gtk2::Ex::Statusbar::Message', | ||
| 37 | properties => [ Glib::ParamSpec->scalar | ||
| 38 | ('jobs', | ||
| 39 | 'jobs', | ||
| 40 | 'Arrayref of App::Chart::Gtk2::Job objects to display.', | ||
| 41 | Glib::G_PARAM_READWRITE) | ||
| 42 | ]; | ||
| 43 | |||
| 44 | # ENHANCE-ME: ConnectProperties onto the first in @$jobs, plus noticing when | ||
| 45 | # it and other jobs are done to remove from list | ||
| 46 | |||
| 47 | sub INIT_INSTANCE { | ||
| 48 | my ($self) = @_; | ||
| 49 | # disconnected in _do_job_status_changed() below when notice weakened away | ||
| 50 | # App::Chart::Gtk2::Job->signal_add_emission_hook | ||
| 51 | # ('status_changed', | ||
| 52 | # \&_do_job_status_changed, | ||
| 53 | # App::Chart::Glib::Ex::MoreUtils::ref_weak($self)); | ||
| 54 | |||
| 55 | require App::Chart::Glib::Ex::EmissionHook; | ||
| 56 | $self->{'hook'} = App::Chart::Glib::Ex::EmissionHook->new | ||
| 57 | ('App::Chart::Gtk2::Job', | ||
| 58 | status_changed => \&_do_job_status_changed, | ||
| 59 | App::Chart::Glib::Ex::MoreUtils::ref_weak($self)); | ||
| 60 | } | ||
| 61 | |||
| 62 | sub SET_PROPERTY { | ||
| 63 | my ($self, $pspec, $newval) = @_; | ||
| 64 | my $pname = $pspec->get_name; | ||
| 65 | $self->{$pname} = $newval; | ||
| 66 | if ($pname eq 'jobs') { | ||
| 67 | _update_status ($self); | ||
| 68 | } | ||
| 69 | } | ||
| 70 | |||
| 71 | sub add_job { | ||
| 72 | my ($self, $job) = @_; | ||
| 73 | my $jobs = $self->{'jobs'}; | ||
| 74 | push @$jobs, $job; | ||
| 75 | if (@$jobs == 1) { | ||
| 76 | _update_status ($self); | ||
| 77 | } | ||
| 78 | $self->notify('jobs'); | ||
| 79 | } | ||
| 80 | |||
| 81 | sub _do_job_status_changed { | ||
| 82 | my ($invocation_hint, $param_list, $ref_weak_self) = @_; | ||
| 83 | ### JobStatusbarMessage _do_job_status_changed() | ||
| 84 | my ($job) = @$param_list; | ||
| 85 | my $self = $$ref_weak_self || return 0; # destroyed, disconnect | ||
| 86 | |||
| 87 | my $jobs = $self->{'jobs'}; | ||
| 88 | if (defined $jobs->[0] && $job == $jobs->[0]) { | ||
| 89 | @$jobs = grep {! $_->is_done} @$jobs; | ||
| 90 | # FIXME: | ||
| 91 | # $self->notify('jobs'); | ||
| 92 | _update_status ($self); | ||
| 93 | } | ||
| 94 | return 1; # stay connected | ||
| 95 | } | ||
| 96 | |||
| 97 | sub _update_status { | ||
| 98 | my ($self) = @_; | ||
| 99 | ### JobStatusbarMessage _update_status() | ||
| 100 | my $job = $self->{'jobs'}->[0]; | ||
| 101 | $self->set_message ($job ? $job->status : undef); | ||
| 102 | } | ||
| 103 | |||
| 104 | 1; | ||
| 105 | __END__ | ||