#!/usr/bin/perl -w
#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;
our $filename;
our $save_as;
sub quit{
Gtk2->main_quit;
}
sub pbar{
while ($test){
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 mp3',
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;# ('wheeeee');
$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->mp3', $main_app_window,
'destroy-with-parent',
'Choisir un fichier flv' => '1',
'sauvegarder sous forme de mp3' => '2',
'convertir' => '3',
"Afficher l'endroit ou se trouve le mp3" => '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;
pbar();
chdir "/tmp";
print "$save_as\n";
system "mplayer -vc null -vo null -ao pcm -benchmark '$filename' ";
system "lame audiodump.wav '$save_as' ";
$test=0;
}
if ($response_id eq '4') {
print "$save_as\n";
}
}
$dialog->show_all;
Gtk2->main;