1
# This file is part of qVamps.
3
# qVamps is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# qVamps is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with qVamps; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24
use Qt::isa qw (Qt::Object);
25
use Qt::attributes qw (proc proc_running log_viewer
26
default_color hilite_errors outbuf);
27
use Qt::slots read_output => [],
29
use QVamps qw (read_setting read_list_setting replace error tr);
33
# DvdMaker (log_viewer, parent, name)
37
my $log_viewer = shift;
39
$this -> SUPER::NEW (@_);
41
my $proc = Qt::Process (this, "DvdMaker::proc");
43
log_viewer = $log_viewer;
44
default_color = $log_viewer -> paletteForegroundColor ();
48
$proc -> setCommunication (&Qt::Process::Stdout | &Qt::Process::Stderr);
50
this -> connect ($proc, SIGNAL "readyReadStdout()", SLOT "read_output()");
51
this -> connect ($proc, SIGNAL "readyReadStderr()", SLOT "read_output()");
52
this -> connect ($proc, SIGNAL "processExited()", SLOT "proc_exited()");
54
$log_viewer -> clear ();
60
# print STDERR "DvdMaker::DESTROY\n";
62
append_output (0, "\n") if (outbuf -> [0]);
63
append_output (1, "\n") if (outbuf -> [1]);
66
parent () -> removeChild (this);
70
default_color = undef;
83
$proc -> setArguments ($args);
85
unless ($proc -> start ())
87
error (sprintf '%s: "%s"',
88
&tr ("Failed launching command"), join (" ", @{$args}));
93
my $event_loop = Qt::Application::eventLoop ();
99
$event_loop -> processEvents (&Qt::EventLoop::WaitForMore);
104
unless ($proc -> normalExit ())
106
log_viewer -> setColor (Qt::Color (0xff, 0, 0));
107
log_viewer -> append (&tr ("Command execution terminated abnormally"));
108
log_viewer -> setColor (default_color);
113
return $proc -> exitStatus ();
122
hilite_errors = $hilite;
125
$lv -> setColor (Qt::Color (0, 0, 0xff));
126
$lv -> append (sprintf "%s \"%s\"\n\n", &tr ("Executing"), $cmd);
127
$lv -> setColor (default_color);
129
$cmd = "exec $cmd" unless ($cmd =~ /[|;]/);
131
return launch ([ "/bin/sh", "-c", $cmd ]);
137
proc -> tryTerminate ();
143
my $e = shift; # 0: stdout, 1: stderr
144
my $s = shift; # string to append
146
# flush output, if string contains backspace
147
my $flush = ($s =~ s/[\b]+//g);
149
# replace return(s) with a newline and remove unwanted lines
151
$s =~ s/^libdvdread: .+\n//mg;
153
$s = outbuf -> [$e] . $s;
154
outbuf -> [$e] = !$flush && ($s =~ s/(.+)\z//) ? $1 : "";
158
$lv -> setColor (Qt::Color (0xff, 0, 0)) if ($e && hilite_errors);
160
$lv -> setColor (default_color);
164
sub read_output : SLOT()
168
while (my $s = $proc -> readStdout ())
170
append_output (0, $s);
173
while (my $s = $proc -> readStderr ())
175
append_output (1, $s);
180
sub proc_exited : SLOT()
188
my $base_path = shift;
189
my $make_menu = shift;
190
my $rm_temps = shift;
197
my $bg_file = parent () -> background_filename ();
198
my $menu_xml = "$base_path/menu/spumux.xml";
199
my $menu_mpg = "$base_path/menu.mpg";
201
if ($bg_file =~ /\.mpe?g$/)
203
$spumux = read_setting ("/Dvdauthor/spumux_mpg");
204
$spumux = replace ($spumux, { "i" => $bg_file,
210
my $video_es = "$base_path/menu/video.mpv";
211
my $prefix = read_setting ("/Installation/prefix");
212
my $audio_es = read_setting ("/Menu/Preferences/audio_es");
213
$audio_es = replace ($audio_es, { "p" => $prefix });
214
$spumux = read_setting ("/Dvdauthor/spumux_mpv");
215
$spumux = replace ($spumux, { "v" => $video_es,
221
$rc = launch_sh_cmd (0, $spumux);
223
rmtree ("$base_path/menu") if ($rm_temps);
232
my $base_path = shift;
233
my $rm_temps = shift;
235
my $vamps_inj = "$base_path/vamps.inj";
237
rmtree ("$base_path/image");
240
my $dvdauthor_xml = "$base_path/dvdauthor.xml";
241
my $dvdauthor = read_setting ("/Dvdauthor/command");
242
$dvdauthor = replace ($dvdauthor, { "x" => $dvdauthor_xml });
244
my $rc = launch_sh_cmd (0, $dvdauthor);
246
unlink ($vamps_inj) if ($rm_temps);
254
my $base_path = shift;
257
my $burner = read_setting ("/General/DVD_burner");
258
my $burn_speed = read_setting ("/General/DVD_burn_speed");
259
my $img_dir = "$base_path/image";
260
my $burn_cmds = read_list_setting ("/Dvdauthor/burn_cmds");
261
my $bcmds_item = read_setting ("/Dvdauthor/burn_cmds_item");
262
my $burn_cmd = $burn_cmds -> [$bcmds_item];
263
$burn_cmd = replace ($burn_cmd, { "d" => $burner,
268
my $rc = launch_sh_cmd (1, $burn_cmd);
276
my $base_path = shift;
277
my $make_menu = shift;
278
my $disk_change = shift;
279
my $rm_temps = shift;
282
my $make_menu_bool = $make_menu ? "true" : "false";
283
my $disk_change_bool = $disk_change ? "true" : "false";
284
my $rm_temps_bool = $rm_temps ? "true" : "false";
285
my $burner = read_setting ("/General/DVD_burner");
286
my $burn_speed = read_setting ("/General/DVD_burn_speed");
287
my $prefix = read_setting ("/Installation/prefix");
288
my $audio_es = read_setting ("/Menu/Preferences/audio_es");
289
$audio_es = replace ($audio_es, { "p" => $prefix });
290
my $bg_file = parent () -> background_filename ();
291
my $menu_ps = $bg_file =~ /\.mpe?g$/ ? $bg_file : "";
293
&tr ("Please insert blank DVD into burner and press <RETURN> key");
294
my $spumux_mpv = read_setting ("/Dvdauthor/spumux_mpv");
295
$spumux_mpv = replace ($spumux_mpv, { "v" => '$video_es',
298
"o" => '$menu_mpg' });
299
my $spumux_mpg = read_setting ("/Dvdauthor/spumux_mpg");
300
$spumux_mpg = replace ($spumux_mpg, { "i" => '$menu_ps',
302
"o" => '$menu_mpg' });
303
my $dvdauthor = read_setting ("/Dvdauthor/command");
304
$dvdauthor = replace ($dvdauthor, { "x" => '$dvdauthor_xml' });
305
my $burn_cmds = read_list_setting ("/Dvdauthor/burn_cmds");
306
my $bcmds_item = read_setting ("/Dvdauthor/burn_cmds_item");
307
my $burn_cmd = $burn_cmds -> [$bcmds_item];
308
$burn_cmd = replace ($burn_cmd, { "d" => '$burner',
309
"s" => '$burn_speed',
311
"i" => '$img_path' });
313
my $file = "$base_path/run_me";
315
unless (open SCR, ">", $file)
317
error (sprintf "%s: %s: %s",
318
&tr ("Failed creating shell script"), $file, $!);
327
make_menu="$make_menu_bool"
328
disk_change="$disk_change_bool"
329
rm_temps="$rm_temps_bool"
331
# settings for burning
333
burn_speed="$burn_speed"
337
base_path="$base_path"
338
img_path="\$base_path/image"
339
dvdauthor_xml="\$base_path/dvdauthor.xml"
340
menu_mpg="\$base_path/menu.mpg"
341
vamps_inj="\$base_path/vamps.inj"
342
menu_path="\$base_path/menu"
343
menu_xml="\$menu_path/spumux.xml"
344
video_es="\$menu_path/video.mpv"
353
if [ -z "\$menu_ps" ]; then
359
\$rm_temps && rm -rf \$menu_path
362
rm -rf \$img_path \$vamps_inj
366
\$rm_temps && rm -f \$vamps_inj
368
\$disk_change && { echo -n "\$prompt"; read x; }
375
chmod 0777 & ~umask (), $file;