#!/usr/bin/perl -w
# use strict;
use POE;
#This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
#This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
#You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
# use strict ;
use Gtk2 '-init' ;
use Time::HiRes qw(usleep);
use constant FALSE => 0;
use constant TRUE =>1;
use Gtk2::Helper;
our $filename;
our $save_as;
sub quit{
Gtk2->main_quit;
}
# sub pbar{
#
# while (1){
# Gtk2->main_iteration while Gtk2->events_pending;
# # $progressbar->set_pulse_step(0.1 ) ;
# $progressbar->pulse;
# usleep(100000);
# }
#
# }
sub file_chooser {
my $file_chooser =
Gtk2::FileChooserDialog->new ('Choose a flash video to convert to xvid',
undef, 'open',
'gtk-cancel' => 'cancel',
'gtk-ok' => 'ok');
# create a preview widget, which will show a quick summary of information
# about the selected file, updated whenever the selection changes.
# note that this assumes you're on a unix-like system with the 'file'
# utility installed.
my $preview_widget = Gtk2::Label->new;
$preview_widget->set_line_wrap (TRUE);
$preview_widget->set_size_request (150, -1);
$file_chooser->set (preview_widget => $preview_widget,
preview_widget_active => TRUE);
$file_chooser->signal_connect (selection_changed => sub {
$filename = $file_chooser->get_preview_filename;
# we'll hide the preview widget if the selected item is a directory.
# in practice, you may find this really annoying, as it causes the
# window to change size.
my $active = defined $filename && not -d $filename;
if ($active) {
my $size = sprintf '%.1fK', (-s $filename) / 1024;
my $desc = `file '$filename'`;
$desc =~ s/^$filename:\s*//;
$preview_widget->set_text ("$size\n$desc");
}
$file_chooser->set (preview_widget_active => $active);
});
# add an app-specific entry to the shortcut list.
# $file_chooser->add_shortcut_folder ('/tmp');
# eval { $file_chooser->add_shortcut_folder_uri ('http://localhost/'); };
# warn "couldn't add shortcut: $@\n" if $@;
if ('ok' eq $file_chooser->run) {
# you can get the user's selection as a filename or a uri.
# my $uri = $file_chooser->get_uri;
# print "uri $uri\n";
# $filename = $file_chooser->get_filename;
# print "$filename\n";
}
$file_chooser->destroy;
}
sub file_saver {
my $dialog = Gtk2::FileChooserDialog->new('Save as',undef,'save',
'gtk-ok', 'ok',
'gtk-cancel', 'cancel');
my $response = $dialog->run(); # this blocks
if ($response eq 'ok') {
$save_as = $dialog->get_filename();
}
$dialog->destroy();
}
# my $message = shift;
my $dialog = Gtk2::Dialog->new ('convertisseur flv->xvid', $main_app_window,
'destroy-with-parent',
'Choisir un fichier flv' => '1',
'sauvegarder sous forme de xvid' => '2',
'convertir' => '3',
"Afficher l'endroit ou se trouve le xvid" => '4'
);
$dialog->signal_connect (response => \&button_response );
$dialog->signal_connect(delete_event => \&quit);
$progressbar = Gtk2::ProgressBar->new;
$dialog->vbox->add ($progressbar);
sub button_response {
my ($dialog, $response_id) = @_;
if ($response_id eq '1') {
file_chooser();
}
if ($response_id eq '2') {
file_saver();
}
if ($response_id eq '3') {
# $test=1;
chdir "/tmp";
# print "$save_as\n";
# open(INPUT, " mplayer -vc null -vo null -ao pcm -benchmark /home/gentux/luniz -slave|");
# && lame audiodump.wav /tmp/luniz.mp3
# open my $input, '-|', "mencoder '$filename' -ovc xvid -oac mp3lame -xvidencopts bitrate=1500 -o '$save_as'";
open my $input, '-|', "mencoder '$filename' -ovc xvid -oac mp3lame -xvidencopts bitrate=1500 -o '$save_as'" or die "can't fork";
# print "$input";
# pbar();
my $process;
$process = Gtk2::Helper->add_watch( fileno( $input ), in => sub {
if ( eof( $input ) ) {
my $finished = Gtk2::Dialog->new ('La conversion est finie', undef,'destroy-with-parent', 'ok' => '4');
$label = Gtk2::Label->new("le mp3 se trouve a l'endroit suivant: $save_as");
$finished->vbox->add ($label);
$finished->signal_connect (response => \&quit );
$finished->show_all;
last;
}
else {
Gtk2->main_iteration while Gtk2->events_pending;
$progressbar->pulse;
usleep(100000);
}
return 1;
} );
#ajouter une fenetre qui indique l'endroit ou se trouve le mp3 a la fin de la conversion et ou on peut appuyer sur ok
# system "mplayer -vc null -vo null -ao pcm -benchmark /home/gentux/luniz && lame audiodump.wav /tmp/luniz.mp3";
# open(LAME, "lame audiodump.wav '$save_as' |");
# open (OUTPUT,">>/home/gentux/input.txt");
# pbar();
# $input = <INPUT>;
# $output = <OUTPUT>;
# open (LF, ">>/home/gentux/lf.txt");
# system (pwd);
# print "----------------------------------------------------------------------------------";
# print MF "$mplayer";
# print OUTPUT "$input";
$test=0;
}
if ($response_id eq '4') {
print "$save_as\n";
}
}
$dialog->show_all;
Gtk2->main;