blib/lib/Video/DVDRip/Term/Main.pm untested

filter: Statementstmt 0.0% 0 / 106 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 32 Podpod 0.0% 0 / 23 totaltotal 0.0% 0 / 185 CC 8 SCAR 16.1
CC
8
Cov
0%
exec_tasks
20.0
open_project
12.0
new
6.0
CRAP 5.0
1 # $Id: Main.pm 2187 2006-08-16 19:34:38Z 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::Term::Main;
12  
13 use base qw( Video::DVDRip::Base );
14  
15 use Locale::TextDomain qw (video.dvdrip);
16  
17 use Carp;
18 use strict;
19  
20 use Video::DVDRip::Project;
21 use Video::DVDRip::Logger;
22 use Video::DVDRip::Term::Progress;
23 use Video::DVDRip::GUI::Pipe;
24 use Video::DVDRip::Term::ExitTask;
25  
26 sub filename { shift->{filename} }
27 sub select_title { shift->{select_title} }
28 sub project { shift->{project} }
29 sub progress { shift->{progress} }
30 sub glib_main_loop { shift->{glib_main_loop} }
31 sub fullscreen { shift->{fullscreen} }
32 sub quiet { shift->{quiet} }
33  
34 sub set_filename { shift->{filename} = $_[1] }
35 sub set_select_title { shift->{select_title} = $_[1] }
36 sub set_project { shift->{project} = $_[1] }
37 sub set_progress { shift->{progress} = $_[1] }
38 sub set_glib_main_loop { shift->{glib_main_loop} = $_[1] }
39 sub set_fullscreen { shift->{fullscreen} = $_[1] }
40 sub set_quiet { shift->{quiet} = $_[1] }
41  
42 sub new {
43 my $class = shift;
44 my %par = @_;
45 my ( $filename, $select_title, $fullscreen, $quiet )
46 = @par{ 'filename', 'select_title', 'fullscreen', 'quiet' };
47  
48 $fullscreen = 0 if $quiet;
49  
50 my $self = bless {
51 filename => $filename,
52 select_title => $select_title,
53 fullscreen => $fullscreen,
54 quiet => $quiet,
55 progress =>
56 Video::DVDRip::Term::Progress->new( quiet => !$fullscreen, ),
57 }, $class;
58  
59 return $self;
60 }
61  
62 sub clear_screen {
63 my $self = shift;
64  
65 $self->print_screen( chr(27) . "[2J" );
66 $self->print_screen( chr(27) . "[0;0H" );
67  
68 my $col = chr(27) . "[1;33m";
69 my $reset = chr(27) . "[0m";
70  
71 $self->print_screen( "[ ${col}dvd::rip $Video::DVDRip::VERSION - "
72 . "(c) 2002-2005 Jörn Reder - "
73 . "Task Execution Terminal$reset ]\n\n" );
74  
75 1;
76 }
77  
78 sub print_screen {
79 my $self = shift;
80 return unless $self->fullscreen;
81 print @_;
82 1;
83 }
84  
85 sub open_project {
86 my $self = shift;
87  
88 my $project
89 = Video::DVDRip::Project->new_from_file( filename => $self->filename,
90 );
91  
92 $self->set_project($project);
93  
94 $self->print_screen( "> Open project file " . $self->filename . "\n" );
95  
96 my $logger = Video::DVDRip::Logger->new( project => $project, );
97  
98 $logger->set_fh( \*STDOUT ) if !$self->quiet && !$self->fullscreen;
99  
100 $self->set_logger($logger);
101  
102 $project->content->set_selected_titles( [ $self->select_title - 1 ] )
103 if $self->select_title;
104  
105 1;
106 }
107  
108 sub exec_tasks {
109 my $self = shift;
110 my ($tasks) = @_;
111  
112 my $first_task;
113 my $last_task;
114 foreach my $task_name ( @{$tasks} ) {
115 $self->log("Loading task module for '$task_name'");
116 my $module = "Video::DVDRip::Task::$task_name";
117 eval "use $module\n";
118 die $@ if $@;
119  
120 my $task = $module->new(
121 ui => $self,
122 project => $self->project,
123 cb_error => sub {
124 $self->glib_main_loop->quit;
125 },
126 );
127 $first_task ||= $task;
128 if ($last_task) {
129 $last_task = $last_task->next_task while $last_task->next_task;
130 $last_task->set_next_task($task);
131 }
132 $last_task = $task;
133 }
134  
135 $last_task->set_next_task(
136 Video::DVDRip::Term::ExitTask->new( ui => $self, ),
137 );
138  
139 $self->print_screen("\n");
140  
141 $first_task->configure;
142 $first_task->start;
143  
144 $self->enter_mainloop;
145 $self->progress->close if $last_task->reuse_progress;
146  
147 1;
148 }
149  
150 sub long_message_window {
151 my $self = shift;
152 my %par = @_;
153 my ($message) = @par{'message'};
154  
155 print $message. "\n";
156  
157 1;
158 }
159  
160 sub message_window {
161 my $self = shift;
162 my %par = @_;
163 my ($message) = @par{'message'};
164  
165 print $message. "\n";
166  
167 1;
168 }
169  
170 sub confirm_window {
171 my $self = shift;
172 my %par = @_;
173 my ($message, $yes_callback, $no_callback, $position) =
174 @par{'message','yes_callback','no_callback','position'};
175 my ($with_cancel) =
176 @par{'with_cancel'};
177  
178 #-- For know just call the yes callback
179 &$yes_callback();
180
181 1;
182 }
183  
184 sub enter_mainloop {
185 my $self = shift;
186  
187 my $main_loop = Glib::MainLoop->new;
188 $self->set_glib_main_loop($main_loop);
189  
190 $main_loop->run;
191  
192 1;
193 }
194 1;