All pastes #409611 Raw Edit

Stuff

public text v1 · immutable
#409611 ·published 2007-03-25 20:35 UTC
rendered paste body
#!/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 constant TRUE => 1 ;
use constant FALSE => 0 ;
our $filename;
our $save_as;


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 $file_chooser2 =
	Gtk2::FileChooserDialog->new ('Save as the mp3',
	                               undef, 'save',
	                              '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_chooser2->set (preview_widget => $preview_widget,
                    preview_widget_active => TRUE);
$file_chooser2->signal_connect (selection_changed => sub {
	$save_as = $file_chooser2->get_preview_filename;
	print "$save_as\n";
	# 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_chooser2->set (preview_widget_active => $active);
});

# add an app-specific entry to the shortcut list.
# $file_chooser2->add_shortcut_folder ('/tmp');
# eval { $file_chooser2->add_shortcut_folder_uri ('http://localhost/'); };
# warn "couldn't add shortcut: $@\n" if $@;
if ('ok' eq $file_chooser2->run) {
	# you can get the user's selection as a filename or a uri.
# 	my $uri = $file_chooser->get_uri;
# 	print "uri $uri\n";
# 	$save_as = $file_chooser2->get_filename;
# 	print "$filename\n";
}

$file_chooser2->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 la variable' => '4'
					   );
#            my $label = Gtk2::Label->new ('Choisir un fichier FLV a convertir puis choisir le fichier a enregistrer puis appuyer sur convertir');
# 	   my $button = Gtk2::Button->new("fichier a ouvrir");
#            $dialog->vbox->add ($label);
# 	   my $main_hbox = Gtk2->HBox->new;
 
# 	 $dialog->vbox->add ($label);
	# Ensure that the dialog box is destroyed when the user responds.
#          $dialog->signal_connect (response => sub {$_[0]->destroy });
         $dialog->signal_connect (response => \&button_response );

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') { 
chdir "/tmp";
print "$save_as\n";
system "mplayer -vc null -vo null -ao pcm -benchmark '$filename' ";
system "lame audiodump.wav '$save_as' ";
#add a widget for having the name of the file
} 


if ($response_id eq '4') { 
print "$save_as\n";
}


}
$dialog->show_all;




Gtk2->main;