blib/lib/Video/DVDRip/GUI/Base.pm

filter: Statementstmt 14.6% 19 / 130 Branchbran 0.0% 0 / 24 Conditioncond 0.0% 0 / 13 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 20.0% 6 / 30 Podpod 0.0% 0 / 18 totaltotal 11.2% 25 / 223 CC 18 SCAR 23.9
CC
18
Cov
11%
show_file_dialog
42.0
get_optimum_screen_size_options
20.0
new
12.0
CRAP 10.9
« blib/lib/Video/DVDRip/GUI/Project/Storage.pm ↑ Summary blib/lib/Event/RPC/Server.pm »
1 # $Id: Base.pm 2341 2007-08-09 21:35:05Z joern $
2  
3 #-----------------------------------------------------------------------
4 # Copyright (C) 2001-2006 Jörn Reder <joern AT zyn.de>.
5 # All Rights Reserved. See file COPYRIGHT for details.
6 #
7 # This module is part of Video::DVDRip, which is free software; you can
8 # redistribute it and/or modify it under the same terms as Perl itself.
9 #-----------------------------------------------------------------------
10  
11 package Video::DVDRip::GUI::Base;
12 1 ▶use Locale::TextDomain qw (video.dvdrip);
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 1 ▶use base Video::DVDRip::Base;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use Cwd;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 0 ▶sub get_context { shift->{context} }
Subroutine get_context: not called CC=1 SCAR=6.9
Pod undocumented
22 0 ▶sub set_context { shift->{context} = $_[1] }
Subroutine set_context: not called CC=1 SCAR=6.9
Pod undocumented
23  
24 0 ▶sub get_form_factory { shift->{form_factory} }
Subroutine get_form_factory: not called CC=1 SCAR=6.9
Pod undocumented
25 0 ▶sub set_form_factory { shift->{form_factory} = $_[1] }
Subroutine set_form_factory: not called CC=1 SCAR=6.9
Pod undocumented
26  
27 0 ▶sub get_context_object { $_[0]->{context}->get_object($_[1]) }
Subroutine get_context_object: not called CC=1 SCAR=6.9
Pod undocumented
28  
29 0 ▶sub new {
Subroutine new: not called CC=3 SCAR=24.8
Pod undocumented
30 0 my $class = shift;
31 0 my %par = @_;
32 0 my ( $form_factory, $context ) = @par{ 'form_factory', 'context' };
33  
34 0 ▶ $context ||= $form_factory->get_context if $form_factory;
Branch: 1 branch
BranchTrueFalseTotal
if $form_factory 0 0 0
Condition0%0/3
$context ||= $form_factory->get_context
l!l&&r!l&&!r
000
MC/DC0%0/2
$context ||= $form_factory->get_context
$context $form_factory->get_context
Truth table0%0/3
A ||= B
A= $contextB= $form_factory->get_context
ABresult
1X1
011
000
35  
36 0 my $self = bless {
37 form_factory => $form_factory,
38 context => $context,
39 }, $class;
40  
41 0 return $self;
42 }
43  
44 0 ▶sub create_text_tag {
Subroutine create_text_tag: not called CC=2 SCAR=17.9
Pod undocumented
45 0 my $self = shift;
46 0 my $name = shift;
47 0 my %par = @_;
48  
49 0 my $cb = delete $par{cb};
50  
51 0 my $tag = Gtk2::TextTag->new($name);
52 0 $tag->set(%par);
53  
54 0 ▶ $tag->signal_connect( "event", $cb ) if $cb;
Branch: 1 branch
BranchTrueFalseTotal
if $cb 0 0 0
55  
56 0 return $tag;
57 }
58  
59 0 ▶sub project {
Subroutine project: not called CC=1 SCAR=6.9
Pod undocumented
60 0 my $self = shift;
61 0 return $self->get_context->get_object("project");
62 }
63  
64 0 ▶sub selected_title {
Subroutine selected_title: not called CC=1 SCAR=6.9
Pod undocumented
65 0 my $self = shift;
66 0 return $self->get_context->get_object("title");
67 }
68  
69 0 ▶sub progress {
Subroutine progress: not called CC=1 SCAR=6.9
Pod undocumented
70 0 my $self = shift;
71 0 return $self->get_context->get_object("progress");
72 }
73  
74 0 ▶sub progress_is_active {
Subroutine progress_is_active: not called CC=1 SCAR=6.9
Pod undocumented
75 0 return $_[0]->progress->is_active;
76 }
77  
78 0 ▶sub show_file_dialog {
Subroutine show_file_dialog: not called CC=6 SCAR=37.4
Pod undocumented
79 0 my $self = shift;
80 0 my %par = @_;
81 my ( $type, $dir, $filename, $cb, $title, $confirm )
82 0 = @par{ 'type', 'dir', 'filename', 'cb', 'title', 'confirm' };
83  
84 0 ▶ $type ||= "open";
Condition0%0/2
$type ||= "open"
l!l
00
MC/DC0%0/1
$type ||= "open"
$type
Truth table0%0/2
A
A= $type
Aresult
11
00
85  
86 0 my $cwd = cwd;
87 0 chdir($dir);
88  
89 0 my $form_factory = $self->get_form_factory;
90 0 ▶ my $gtk_window =
Branch: 1 branch
BranchTrueFalseTotal
$form_factory ? : 0 0 0
91 $form_factory
92 ? $form_factory->get_form_factory_gtk_window
93 : undef;
94  
95 # Create a new file selection widget
96 0 my $dialog = Gtk2::FileChooserDialog->new(
97 $title,
98 $gtk_window,
99 "save",
100 'gtk-cancel' => 'cancel',
101 'gtk-ok' => 'ok'
102 );
103  
104 0 $dialog->set_current_name($filename);
105  
106 0 my $response = $dialog->run;
107  
108 0 my $filename = $dialog->get_filename;
109  
110 0 $dialog->destroy;
111 0 chdir($cwd);
112  
113 0 ▶ if ( $response eq 'ok' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($response eq "ok") 0 0 0
114 0 ▶ if ( -f $filename and $confirm ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f $filename and $confirm) { } 0 0 0
Condition0%0/3
-f $filename and $confirm
!ll&&!rl&&r
000
MC/DC0%0/2
-f $filename and $confirm
-f $filename $confirm
Truth table0%0/3
A and B
A= -f $filenameB= $confirm
ABresult
0X0
100
111
115 $self->confirm_window(
116 message => __x(
117 "Overwrite existing file '{filename}'?",
118 filename => $filename
119 ),
120 0 ▶ yes_callback => sub { &$cb($filename) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
121 0 );
122 }
123 else {
124 0 &$cb($filename);
125 }
126 }
127  
128 0 1;
129 }
130  
131 0 ▶sub message_window {
Subroutine message_window: not called CC=2 SCAR=17.9
Pod undocumented
132 0 my $self = shift;
133 0 my %par = @_;
134 my ($message, $ff, $modal, $type) =
135 0 @par{'message','ff','modal','type'};
136  
137 0 ▶ $type ||= "info";
Condition0%0/2
$type ||= "info"
l!l
00
MC/DC0%0/1
$type ||= "info"
$type
Truth table0%0/2
A
A= $type
Aresult
11
00
138  
139 0 my $dialog = Gtk2::MessageDialog->new_with_markup( undef,
140 ["destroy-with-parent"], $type, "none", $message );
141  
142 0 $dialog->set_position("center-on-parent");
143 0 $dialog->set_modal($modal);
144 0 $dialog->add_buttons( "gtk-ok", "ok" );
145  
146 $dialog->signal_connect(
147 "response",
148 0 ▶ sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
149 0 my ( $widget, $answer ) = @_;
150 0 $widget->destroy;
151 0 1;
152 }
153 0 );
154  
155 0 $dialog->show;
156  
157 0 1;
158  
159 }
160  
161 0 ▶sub error_window {
Subroutine error_window: not called CC=3 SCAR=24.8
Pod undocumented
162 0 my $self = shift;
163 0 my %par = @_;
164 0 my ($message) = @par{'message'};
165  
166 0 ▶ if ( $message =~ s/^msg:// ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($message =~ s/^msg://) 0 0 0
167 0 $message =~ s/\s+at\s+.*?line\s+\d+//;
168 }
169  
170 0 ▶ if ( length($message) > 500 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $message > 500) 0 0 0
171 0 return $self->long_message_window(
172 message => $message,
173 title => __ "Error message"
174 );
175 }
176  
177 0 my $dialog = Gtk2::MessageDialog->new( undef,
178 [ "modal", "destroy-with-parent" ],
179 "error", "none", $message );
180  
181 0 $dialog->set_position("center-on-parent");
182 0 $dialog->add_buttons( "gtk-ok", "ok" );
183  
184 $dialog->signal_connect(
185 "response",
186 0 ▶ sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
187 0 my ( $widget, $answer ) = @_;
188 0 $widget->destroy;
189 0 1;
190 }
191 0 );
192  
193 0 $dialog->show;
194  
195 0 1;
196  
197 }
198  
199 0 ▶sub long_message_window {
Subroutine long_message_window: not called CC=3 SCAR=24.8
Pod undocumented
200 0 my $self = shift;
201 0 my %par = @_;
202 0 my ( $message, $title, $fixed ) = @par{ 'message', 'title', 'fixed' };
203  
204 0 my $frame_title = $title;
205  
206 0 ▶ $title = "dvd::rip - " . $title if $title;
Branch: 1 branch
BranchTrueFalseTotal
if $title 0 0 0
207 0 ▶ $title ||= __ "dvd::rip - Message";
Condition0%0/3
$title ||= &__("dvd::rip - Message")
l!l&&r!l&&!r
000
MC/DC0%0/2
$title ||= &__("dvd::rip - Message")
$title &__("dvd::rip - Message")
Truth table0%0/3
A ||= B
A= $titleB= &__("dvd::rip - Message")
ABresult
1X1
011
000
208  
209 0 my $ff;
210 $ff = Gtk2::Ex::FormFactory->new(
211 sync => 1,
212 content => [
213 Gtk2::Ex::FormFactory::Window->new(
214 title => $title,
215 0 ▶ closed_hook => sub { $ff->close },
Subroutine __ANON__: not called CC=1 SCAR=6.9
216 0 ▶ customize_hook => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
217 0 my ($gtk_window) = @_;
218 0 $_[0]->parent->set(
219 default_width => 600,
220 default_height => 440,
221 );
222 0 1;
223 },
224 content => [
225 Gtk2::Ex::FormFactory::VBox->new(
226 expand => 1,
227 content => [
228 Gtk2::Ex::FormFactory::VBox->new(
229 title => $frame_title,
230 expand => 1,
231 content => [
232 Gtk2::Ex::FormFactory::TextView->new(
233 scrollbars => [ "never", "always" ],
234 expand => 1,
235 properties => {
236 editable => 0,
237 cursor_visible => 0,
238 wrap_mode => "word",
239 },
240 0 ▶ customize_hook => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
241 0 my ($gtk_text_view) = @_;
242 0 ▶ if ($fixed) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fixed) 0 0 0
243 0 my $font
244 = Gtk2::Pango::FontDescription
245 ->from_string("mono");
246 0 $gtk_text_view->modify_font(
247 $font);
248 }
249 $gtk_text_view->get_buffer
250 0 ->set_text($message);
251 0 1;
252 },
253 0 ),
254 ],
255 ),
256 Gtk2::Ex::FormFactory::DialogButtons->new,
257 ],
258 ),
259 ],
260 ),
261 ],
262 );
263  
264 0 $ff->build;
265 0 $ff->update;
266 0 $ff->show;
267  
268 0 1;
269 }
270  
271 0 ▶sub confirm_window {
Subroutine confirm_window: not called CC=1 SCAR=6.9
Pod undocumented
272 0 my $self = shift;
273 0 my %par = @_;
274 my ( $message, $yes_callback, $no_callback, $position, $with_cancel )
275 = @par{
276 0 'message', 'yes_callback', 'no_callback', 'position',
277 'with_cancel'
278 };
279  
280 0 $self->get_form_factory->open_confirm_window(
281 message => $message,
282 yes_callback => $yes_callback,
283 no_callback => $no_callback,
284 position => $position,
285 with_cancel => $with_cancel,
286 );
287  
288 0 1;
289 }
290  
291 0 ▶sub new_job_executor {
Subroutine new_job_executor: not called CC=1 SCAR=6.9
Pod undocumented
292 0 my $self = shift;
293  
294 0 return Video::DVDRip::GUI::ExecuteJobs->new(
295 form_factory => $self->get_form_factory,
296 @_,
297 );
298 }
299  
300 0 ▶sub get_optimum_screen_size_options {
Subroutine get_optimum_screen_size_options: not called CC=4 SCAR=30.0
Pod undocumented
301 0 my $self = shift;
302 0 my ($type) = @_;
303  
304 0 ▶ return () if not $self->config("small_screen");
Branch: 1 branch
BranchTrueFalseTotal
unless $self->config("small_screen") 0 0 0
305  
306 0 ▶ if ( $type eq 'page' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq 'page') { } 0 0 0
elsif ($type eq 'notebook') { } 0 0 0
307 return (
308 0 scrollbars => [ "automatic", "automatic" ],
309 properties => { border_width => 8 },
310 );
311 }
312 elsif ( $type eq 'notebook' ) {
313 return (
314 0 properties => { tab_pos => "left" },
315 );
316 }
317 }
318  
319 1 1;
« blib/lib/Video/DVDRip/GUI/Project/Storage.pm ↑ Summary blib/lib/Event/RPC/Server.pm »