blib/lib/Video/DVDRip/GUI/Project/Title.pm untested

filter: Statementstmt 0.0% 0 / 130 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 24 MC/DCmcdc 0.0% 0 / 14 Subroutinesub 0.0% 0 / 16 Podpod 0.0% 0 / 11 totaltotal 0.0% 0 / 211 CC 9 SCAR 19.8
CC
9
Cov
0%
view_title
20.0
build_factory
12.0
ask_read_dvd_toc
6.0
CRAP 7.2
1 # $Id: Title.pm 2344 2007-08-09 21:37:41Z 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::Project::Title;
12  
13 use base qw( Video::DVDRip::GUI::Base );
14  
15 use Locale::TextDomain qw (video.dvdrip);
16  
17 use Carp;
18 use strict;
19  
20 use File::Path;
21  
22 sub new {
23 my $class = shift;
24  
25 my $self = $class->SUPER::new(@_);
26  
27 $self->get_context->set_object( "toc_gui" => $self );
28  
29 return $self;
30 }
31  
32  
33 sub build_factory {
34 my $self = shift;
35  
36 my $context = $self->get_context;
37  
38 return Gtk2::Ex::FormFactory::VBox->new(
39 $self->get_optimum_screen_size_options("page"),
40 title => '[gtk-cdrom]'.__"RIP Title",
41 object => "project",
42 active_cond => sub {
43 $self->project
44 && $self->project->created;
45 },
46 active_depends => "project.created",
47 no_frame => 1,
48 content => [
49 Gtk2::Ex::FormFactory::HBox->new(
50 name => "dvd_toc_buttons",
51 title => __ "Read content",
52 content => [
53 Gtk2::Ex::FormFactory::Button->new(
54 object => "project",
55 label => __ "Read DVD table of contents",
56 tip => __ "Scan the DVD for all available titles "
57 . "and setup the table of contents",
58 stock => "gtk-find",
59 clicked_hook => sub { $self->ask_read_dvd_toc },
60 active_cond => sub { !$self->progress_is_active },
61 active_depends => "progress.is_active",
62 ),
63 Gtk2::Ex::FormFactory::Button->new(
64 object => "project",
65 label => __ "Open DVD tray",
66 tip => __
67 "Open the tray of your configured DVD device",
68 stock => "gtk-open",
69 clicked_hook => sub { $self->eject_dvd },
70 active_cond => sub {
71 $self->project
72 && !-d $self->project->dvd_device
73 && !$self->progress_is_active
74 },
75 active_depends => [
76 "project.dvd_device",
77 "progress.is_active",
78 ],
79 ),
80 Gtk2::Ex::FormFactory::Button->new(
81 object => "project",
82 label => __ "Close DVD tray",
83 tip => __
84 "Close the tray of your configuried DVD device",
85 stock => "gtk-close",
86 clicked_hook => sub { $self->insert_dvd },
87 active_cond => sub {
88 $self->project
89 && !-d $self->project->dvd_device
90 && !$self->progress_is_active
91 },
92 active_depends => [
93 "project.dvd_device",
94 "progress.is_active",
95 ],
96 ),
97 ]
98 ),
99 Gtk2::Ex::FormFactory::VBox->new(
100 title => __ "DVD table of contents",
101 expand => 1,
102 object => "content",
103 content => [
104 Gtk2::Ex::FormFactory::HBox->new(
105 expand => 1,
106 content => [
107 Gtk2::Ex::FormFactory::List->new(
108 name => "content_list",
109 attr => "content.titles",
110 attr_select => "content.selected_titles",
111 attr_select_column => 0,
112 tip => __"Select title for further operation",
113 expand => 1,
114 scrollbars => [ "never", "automatic" ],
115 columns => [
116 "idx",
117 __ "Title",
118 __ "Runtime",
119 __ "Norm",
120 __ "Chp",
121 __ "Audio",
122 __ "Framerate",
123 __ "Aspect",
124 __ "Frames",
125 __ "Resolution"
126 ],
127 selection_mode => "multiple",
128 customize_hook => sub {
129 my ($gtk_simple_list) = @_;
130 ( $gtk_simple_list->get_columns )[0]
131 ->set( visible => 0 );
132 1;
133 },
134 ),
135 $self->build_audio_viewing_chapter_factory,
136 ]
137 ),
138 Gtk2::Ex::FormFactory::HBox->new(
139 object => "title",
140 content => [
141 Gtk2::Ex::FormFactory::Button->new(
142 label => __ "View selected title/chapter(s)",
143 stock => "gtk-media-play",
144 clicked_hook => sub { $self->view_title },
145 active_cond => sub { !$self->progress_is_active },
146 active_depends => "progress.is_active",
147 ),
148 Gtk2::Ex::FormFactory::Button->new(
149 label => __
150 "RIP selected title(s)/chapter(s)",
151 stock => "gtk-harddisk",
152 clicked_hook => sub { $self->rip_title },
153 active_cond => sub {
154 return 1 unless $self->project;
155 return 0 if $self->project->rip_mode ne 'rip';
156 return !$self->progress_is_active;
157 },
158 active_depends => [ "project.rip_mode", "progress.is_active" ],
159 ),
160  
161 ],
162 ),
163 ],
164 ),
165 ],
166 );
167 }
168  
169 sub build_audio_viewing_chapter_factory {
170 my $self = shift;
171  
172 return Gtk2::Ex::FormFactory::VBox->new(
173 object => "title",
174 content => [
175 Gtk2::Ex::FormFactory::Popup->new(
176 name => "audio_selection", # Title->audio_channel_list requires this
177 attr => "title.audio_channel",
178 label => __ "Select audio track",
179 tip => __ "All audio tracks are ripped, but this "
180 . "track is also scanned for volume while "
181 . "ripping",
182 active_cond => sub {
183 $self->get_context_object("title")
184 && $self->get_context_object("title")->audio_channel
185 != -1;
186 },
187 active_depends => ["title.audio_channel"],
188 ),
189 Gtk2::Ex::FormFactory::Popup->new(
190 attr => "title.tc_viewing_angle",
191 label => "\n" . __ "Select viewing angle",
192 tip => __ "This selection affects ripping, so you "
193 . "must rip again if you change this later",
194 active_cond => sub {
195 $self->get_context_object("title")
196 && $self->get_context_object("title")->viewing_angles
197 > 1;
198 },
199 active_depends => ["title.viewing_angles"],
200 ),
201 Gtk2::Ex::FormFactory::HBox->new(
202 object => "subtitle",
203 label => "\n" . __ "Grab subtitle preview images",
204 content => [
205 Gtk2::Ex::FormFactory::RadioButton->new(
206 attr => "title.tc_rip_subtitle_mode",
207 value => "0",
208 label => __ "No",
209 tip => __
210 "No subitle images are created while ripping "
211 . "but can be grabbed later on demand. This is "
212 . "the fastest ripping mode.",
213 ),
214 Gtk2::Ex::FormFactory::RadioButton->new(
215 attr => "title.tc_rip_subtitle_mode",
216 value => "all",
217 label => __ "All",
218 tip => __
219 "Images of all subtitle streams are created "
220 . "during ripping and available for preview "
221 . "immediately. Note that this will slow down "
222 . "the ripping process significantly.",
223 ),
224 Gtk2::Ex::FormFactory::RadioButton->new(
225 attr => "title.tc_rip_subtitle_mode",
226 value => "lang",
227 label => __ "By language",
228 tip => __
229 "Grab subtitle images of specific languages only. "
230 . "Note that this will slow down the ripping process "
231 . "significantly.",
232 ),
233 ],
234  
235 # active_cond => sub { $self->version("spuunmux") >= 611 },
236 # inactive => "invisible",
237 ),
238 Gtk2::Ex::FormFactory::List->new(
239 name => "sub_lang_selection",
240 attr => "title.subtitle_languages",
241 attr_select => "title.tc_rip_subtitle_lang",
242 attr_select_column => 0,
243 expand => 0,
244 height => 75,
245 scrollbars => [ "never", "always" ],
246 tip => __ "Select one or more languages",
247 columns => [ __ "Language selection" ],
248 selection_mode => "multiple",
249 inactive => "invisible",
250 ),
251 Gtk2::Ex::FormFactory::HBox->new(
252 object => "title",
253 label => "\n" . __ "Specify chapter mode",
254 content => [
255 Gtk2::Ex::FormFactory::RadioButton->new(
256 attr => "title.tc_use_chapter_mode",
257 value => "0",
258 label => __ "None",
259 tip => __ "The title is handled as a whole "
260 . "ignoring all chapter marks",
261 ),
262 Gtk2::Ex::FormFactory::RadioButton->new(
263 attr => "title.tc_use_chapter_mode",
264 value => "all",
265 label => __ "All",
266 tip => __ "Processing is divided into "
267 . "chapters. You get one file per "
268 . "chapter for all chapters of this title",
269 ),
270 Gtk2::Ex::FormFactory::RadioButton->new(
271 attr => "title.tc_use_chapter_mode",
272 value => "select",
273 label => __ "Selection",
274 tip => __ "Processing is divided into "
275 . "chapters. You get one file per "
276 . "chapter for a specific selection "
277 . "of chapters",
278 ),
279 ],
280 ),
281 Gtk2::Ex::FormFactory::List->new(
282 name => "chapter_selection",
283 attr => "title.chapter_list",
284 attr_select => "title.tc_selected_chapters",
285 attr_select_column => 0,
286 expand => 1,
287 scrollbars => [ "never", "always" ],
288 tip => __ "Select one or more chapters",
289 columns => [ "nr", __ "Chapter selection" ],
290 visible => [ 0, 1 ],
291 selection_mode => "multiple",
292 inactive => "invisible",
293 ),
294 ],
295 );
296 }
297  
298 sub ask_read_dvd_toc {
299 my $self = shift;
300  
301 if ( $self->project->content->titles ) {
302 $self->get_form_factory->open_confirm_window(
303 message => __ "If you re-read the TOC, all settings in\n"
304 . "this project get lost. Probably you want\n"
305 . "to save the project to another file before\n"
306 . "you proceeed.\n\n"
307 . "Do you want to re-read the TOC now?",
308 yes_callback => sub { $self->read_dvd_toc },
309 yes_label => __ "Yes",
310  
311 );
312 }
313 else {
314 return $self->read_dvd_toc;
315 }
316 }
317  
318 sub read_dvd_toc {
319 my $self = shift;
320  
321 return if $self->progress_is_active;
322  
323 $self->clear_content_list;
324 $self->get_context->set_object( "title", undef );
325  
326 my $job_planner = $self->get_context->get_object("job_planner");
327 my $exec_flow_gui = $self->get_context->get_object("exec_flow_gui");
328
329 my $job = $job_planner->build_read_toc_job();
330  
331 $job->get_post_callbacks->add (sub{
332 $self->project->content->select_longest_title;
333 $self->get_context->update_object_widgets("content");
334 $self->get_context->update_object_attr_widgets("content.selected_titles");
335 $self->get_context->get_proxy("project")->set_object_changed(1);
336 });
337  
338 $exec_flow_gui->start_job($job);
339  
340 1;
341 }
342  
343 sub clear_content_list {
344 my $self = shift;
345  
346 my $content = $self->project->content;
347  
348 $content->set_titles( {} );
349 $content->set_selected_titles( [] );
350  
351 $self->get_context->update_object_widgets("content");
352 $self->get_context->update_object_widgets("title");
353  
354 1;
355 }
356  
357 sub append_content_list {
358 my $self = shift;
359 my %par = @_;
360 my ($title) = @par{'title'};
361  
362 my $list = $self->get_form_factory->get_widget("content_list");
363  
364 push @{ $list->get_gtk_widget->{data} },
365 [
366 ( $title->nr - 1 ),
367 $title->nr,
368 $self->format_time( time => $title->runtime ),
369 uc( $title->video_mode ),
370 $title->chapters,
371 scalar( @{ $title->audio_tracks } ),
372 $title->frame_rate,
373 $title->aspect_ratio,
374 $title->frames,
375 $title->width . "x" . $title->height
376 ];
377  
378 1;
379 }
380  
381 sub rip_title {
382 my $self = shift;
383  
384 return if $self->progress_is_active;
385  
386 my $job_planner = $self->get_context->get_object("job_planner");
387 my $exec_flow_gui = $self->get_context->get_object("exec_flow_gui");
388
389 my $rip_job = $job_planner->build_rip_job();
390
391 $rip_job->get_post_callbacks->add (sub{
392 $self->get_context->update_object_widgets("title");
393 $self->get_context->update_object_widgets("audio_track");
394 $self->get_context->update_object_widgets("subtitle");
395 $self->get_context->get_proxy("project")->set_object_changed(1);
396 });
397
398 $exec_flow_gui->start_job($rip_job);
399  
400 1;
401 }
402  
403 sub view_title {
404 my $self = shift;
405  
406 my $title = $self->selected_title;
407  
408 if ( not $title ) {
409 $self->message_window( message => __ "Please select a title." );
410 return;
411 }
412  
413 if ( $title->tc_use_chapter_mode eq 'select' ) {
414 my $chapters = $title->tc_selected_chapters;
415 if ( not $chapters or not @{$chapters} ) {
416 $self->message_window( message => __ "No chapters selected." );
417 return;
418 }
419 }
420  
421 my $command = $title->get_view_dvd_command(
422 command_tmpl => $self->config('play_dvd_command') );
423  
424 $self->log("Executing view command: $command");
425  
426 system( $command. " &" );
427  
428 1;
429 }
430  
431 sub eject_dvd {
432 my $self = shift;
433  
434 my $title = $self->selected_title;
435  
436 my $command
437 = $self->config('eject_command') . " " .
438 $title->project->dvd_device;
439  
440 system("$command &");
441  
442 1;
443 }
444  
445 sub insert_dvd {
446 my $self = shift;
447  
448 my $title = $self->selected_title;
449  
450 my $command = $self->config('eject_command') . " -t "
451 . $title->project->dvd_device;
452  
453 system("$command &");
454  
455 1;
456 }
457  
458 1;