App/Chart/Gtk2/JobStopMenu.pm

filter: Statementstmt 81.8% 9 / 11 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod n/a totaltotal 86.6% 13 / 15 CC 1 SCAR 0.7
CC
1
Cov
82%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« App/Chart/Gtk2/JobStatusbarMessage.pm ↑ Summary App/Chart/Gtk2/TickerMain.pm »
1 # Copyright 2008, 2009, 2010, 2011 Kevin Ryde
2  
3 # This file is part of Chart.
4 #
5 # Chart is free software; you can redistribute it and/or modify it under the
6 # terms of the GNU General Public License as published by the Free Software
7 # Foundation; either version 3, or (at your option) any later version.
8 #
9 # Chart is distributed in the hope that it will be useful, but WITHOUT ANY
10 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12 # details.
13 #
14 # You should have received a copy of the GNU General Public License along
15 # with Chart. If not, see <http://www.gnu.org/licenses/>.
16  
17 package App::Chart::Gtk2::JobStopMenu;
18 1 ▶use 5.008;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 0 ▶use Gtk2;
Subroutine BEGIN: called CC=1 SCAR=2.6
22 # use Locale::TextDomain ('App-Chart');
23  
24 use App::Chart::Glib::Ex::MoreUtils;
25 use Glib::Ex::SignalIds;
26 use App::Chart;
27 use App::Chart::Gtk2::Job;
28  
29  
30 use Glib::Object::Subclass
31 'Gtk2::Menu',
32 properties => [ Glib::ParamSpec->object
33 ('job',
34 'job',
35 'App::Chart::Gtk2::Job object to act on, or undef.',
36 'App::Chart::Gtk2::Job',
37 Glib::G_PARAM_READWRITE),
38 ];
39  
40 sub INIT_INSTANCE {
41 my ($self) = @_;
42  
43 # avoid selecting Stop too easily
44 $self->append (Gtk2::SeparatorMenuItem->new);
45 {
46 my $item = $self->{'stop'}
47 = Gtk2::ImageMenuItem->new_from_stock ('gtk-stop');
48 $self->append ($item);
49 $item->signal_connect (activate => \&_do_stop);
50 $item->show;
51 }
52 {
53 my $item = $self->{'delete'}
54 = Gtk2::ImageMenuItem->new_from_stock ('gtk-delete');
55 $self->append ($item);
56 $item->signal_connect (activate => \&_do_delete);
57 $item->show;
58 }
59 }
60  
61 sub SET_PROPERTY {
62 my ($self, $pspec, $newval) = @_;
63 my $pname = $pspec->get_name;
64 $self->{$pname} = $newval; # per default GET_PROPERTY
65  
66 if ($pname eq 'job') {
67 my $job = $newval;
68 $self->{'job_ids'} = $job && Glib::Ex::SignalIds->new
69 ($job,
70 $job->signal_connect ('notify::status' => \&_do_job_status_change,
71 App::Chart::Glib::Ex::MoreUtils::ref_weak($self)));
72 _update_sensitive ($self);
73 }
74 }
75  
76 # "Stop" item activate
77 sub _do_stop {
78 my ($item) = @_;
79 my $self = $item->get_toplevel;
80 if (my $job = $self->{'job'}) {
81 $job->stop;
82 }
83 }
84  
85 # "Delete" item activate
86 sub _do_delete {
87 my ($item) = @_;
88 my $self = $item->get_toplevel;
89 if (my $job = $self->{'job'}) {
90 $job->delete;
91 }
92 }
93  
94 # 'notify::status' on current job (if any)
95 sub _do_job_status_change {
96 my ($job, $pspec, $ref_weak_self) = @_;
97 my $self = $$ref_weak_self || return;
98 _update_sensitive ($self);
99 }
100  
101 sub _update_sensitive {
102 my ($self) = @_;
103 my $job = $self->{'job'};
104  
105 my $stop = $self->{'stop'};
106 $stop->set_sensitive ($job && $job->is_stoppable);
107  
108 my $delete = $self->{'delete'};
109 $delete->set_sensitive ($job && $job->is_done);
110 }
111  
112 sub popup_from_treeview {
113 my ($self, $event, $treeview) = @_;
114  
115 my ($path) = $treeview->get_path_at_pos ($event->x, $event->y);
116 if (! $path) { return; }
117  
118 my $model = $treeview->get_model; # App::Chart::Gtk2::JobQueue
119 my $iter = $model->get_iter ($path);
120 my $job = $model->get_value ($iter, 0);
121 $self->set (job => $job);
122 $self->set_screen ($treeview->get_screen);
123 $self->popup (undef, undef, undef, undef, $event->button, $event->time);
124 }
125  
126 1;
127 __END__
« App/Chart/Gtk2/JobStatusbarMessage.pm ↑ Summary App/Chart/Gtk2/TickerMain.pm »