| 1 | # $Id: MultiAudio.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::GUI::MultiAudio; | ||
| 12 | use Locale::TextDomain qw (video.dvdrip); | ||
| 13 | |||
| 14 | use base qw(Video::DVDRip::GUI::Base); | ||
| 15 | |||
| 16 | use strict; | ||
| 17 | use Carp; | ||
| 18 | |||
| 19 | my $multi_audio_ff; | ||
| 20 | |||
| 21 | sub open_window { | ||
| 22 | my $self = shift; | ||
| 23 | |||
| 24 | return if $multi_audio_ff; | ||
| 25 | |||
| 26 | $self->build; | ||
| 27 | |||
| 28 | 1; | ||
| 29 | } | ||
| 30 | |||
| 31 | sub build { | ||
| 32 | my $self = shift; | ||
| 33 | |||
| 34 | my $context = $self->get_context; | ||
| 35 | |||
| 36 | $context->set_object( multi_audio => $self ); | ||
| 37 | |||
| 38 | $multi_audio_ff = Gtk2::Ex::FormFactory->new( | ||
| 39 | context => $context, | ||
| 40 | parent_ff => $self->get_form_factory, | ||
| 41 | sync => 1, | ||
| 42 | content => [ | ||
| 43 | Gtk2::Ex::FormFactory::Window->new( | ||
| 44 | title => __ "dvd::rip - Manage multiple audio tracks", | ||
| 45 | closed_hook => sub { | ||
| 46 | $multi_audio_ff->close if $multi_audio_ff; | ||
| 47 | $multi_audio_ff = undef; | ||
| 48 | $context->set_object( multi_audio => undef ); | ||
| 49 | 1; | ||
| 50 | }, | ||
| 51 | content => [ | ||
| 52 | Gtk2::Ex::FormFactory::VBox->new( | ||
| 53 | expand => 1, | ||
| 54 | content => [ | ||
| 55 | $self->build_multi_audio_table, | ||
| 56 | Gtk2::Ex::FormFactory::DialogButtons->new( | ||
| 57 | clicked_hook_after => sub { | ||
| 58 | $multi_audio_ff->close if $multi_audio_ff; | ||
| 59 | $multi_audio_ff = undef; | ||
| 60 | $context->set_object( | ||
| 61 | multi_audio => undef ); | ||
| 62 | }, | ||
| 63 | ), | ||
| 64 | ], | ||
| 65 | ), | ||
| 66 | ], | ||
| 67 | ), | ||
| 68 | |||
| 69 | ], | ||
| 70 | ); | ||
| 71 | |||
| 72 | $multi_audio_ff->build; | ||
| 73 | $multi_audio_ff->update; | ||
| 74 | $multi_audio_ff->show; | ||
| 75 | |||
| 76 | 1; | ||
| 77 | } | ||
| 78 | |||
| 79 | sub build_multi_audio_table { | ||
| 80 | my $self = shift; | ||
| 81 | |||
| 82 | return Gtk2::Ex::FormFactory::Table->new( | ||
| 83 | title => __ "Manage multiple audio tracks", | ||
| 84 | expand => 1, | ||
| 85 | layout => " | ||
| 86 | +[--------------+-----%-----+ | ||
| 87 | | Label | Label | | ||
| 88 | +---------------+-----------+ | ||
| 89 | | Matrix | | ||
| 90 | +---------------------------+ | ||
| 91 | ", | ||
| 92 | content => [ | ||
| 93 | Gtk2::Ex::FormFactory::Label->new( | ||
| 94 | label => "<b>" . __("Source tracks") . "</b>", | ||
| 95 | with_markup => 1, | ||
| 96 | ), | ||
| 97 | Gtk2::Ex::FormFactory::Label->new( | ||
| 98 | label => "<b>" . __("Target tracks") . "</b>", | ||
| 99 | with_markup => 1, | ||
| 100 | ), | ||
| 101 | Gtk2::Ex::FormFactory::CheckButtonGroup->new( | ||
| 102 | attr => "multi_audio.matrix", | ||
| 103 | attr_max_columns => "multi_audio.max_columns", | ||
| 104 | attr_row_labels => "multi_audio.row_labels", | ||
| 105 | attr_column_labels => "multi_audio.column_labels", | ||
| 106 | homogeneous => 0, | ||
| 107 | changed_hook => sub { $self->matrix_changed( $_[1] ) }, | ||
| 108 | ) | ||
| 109 | ], | ||
| 110 | ); | ||
| 111 | } | ||
| 112 | |||
| 113 | sub max_columns { | ||
| 114 | my $self = shift; | ||
| 115 | return 1 + @{ $self->selected_title->audio_tracks }; | ||
| 116 | } | ||
| 117 | |||
| 118 | sub row_labels { | ||
| 119 | my $self = shift; | ||
| 120 | my @labels; | ||
| 121 | my $i = 1; | ||
| 122 | push @labels, "[" . $i++ . "] " . $_->info . " " | ||
| 123 | for @{ $self->selected_title->audio_tracks }; | ||
| 124 | return \@labels; | ||
| 125 | } | ||
| 126 | |||
| 127 | sub column_labels { | ||
| 128 | my $self = shift; | ||
| 129 | my @labels; | ||
| 130 | push @labels, "[$_] " | ||
| 131 | for 1 .. @{ $self->selected_title->audio_tracks }; | ||
| 132 | push @labels, "[" . __("Discard") . "]"; | ||
| 133 | return \@labels; | ||
| 134 | } | ||
| 135 | |||
| 136 | sub matrix { | ||
| 137 | my $self = shift; | ||
| 138 | |||
| 139 | my %matrix; | ||
| 140 | my $audio_tracks = $self->selected_title->audio_tracks; | ||
| 141 | |||
| 142 | my $i = 0; | ||
| 143 | foreach my $track ( @{$audio_tracks} ) { | ||
| 144 | $matrix{ "$i:" . $track->tc_target_track } = 1; | ||
| 145 | ++$i; | ||
| 146 | } | ||
| 147 | |||
| 148 | return \%matrix; | ||
| 149 | } | ||
| 150 | |||
| 151 | sub set_matrix {undef} | ||
| 152 | |||
| 153 | sub matrix_list { | ||
| 154 | my $self = shift; | ||
| 155 | |||
| 156 | my $track_cnt = @{ $self->selected_title->audio_tracks }; | ||
| 157 | |||
| 158 | my @matrix; | ||
| 159 | for ( my $target = 0; $target < $track_cnt; ++$target ) { | ||
| 160 | for ( my $source = 0; $source < $track_cnt; ++$source ) { | ||
| 161 | push @matrix, [ "$source:$target", "" ],; | ||
| 162 | } | ||
| 163 | } | ||
| 164 | |||
| 165 | for ( my $source = 0; $source < $track_cnt; ++$source ) { | ||
| 166 | push @matrix, [ "$source:-1", "" ],; | ||
| 167 | } | ||
| 168 | |||
| 169 | return \@matrix; | ||
| 170 | } | ||
| 171 | |||
| 172 | sub matrix_changed { | ||
| 173 | my $self = shift; | ||
| 174 | my ($check_button_group) = @_; | ||
| 175 | |||
| 176 | my $title = $self->selected_title; | ||
| 177 | my $audio_tracks = $title->audio_tracks; | ||
| 178 | my $value = $check_button_group->get_last_toggled_value; | ||
| 179 | |||
| 180 | my ( $source, $target ) = split( ":", $value ); | ||
| 181 | |||
| 182 | if ( !$check_button_group->get_gtk_check_buttons->{$value}->get_active | ||
| 183 | || $target == -1 ) { | ||
| 184 | |||
| 185 | #-- checked button clicked again or track disabled | ||
| 186 | $audio_tracks->[$source]->set_tc_target_track(-1); | ||
| 187 | $check_button_group->update_selection; | ||
| 188 | |||
| 189 | } | ||
| 190 | else { | ||
| 191 | |||
| 192 | #-- check if any track is assigned to this target track already | ||
| 193 | foreach my $track ( @{$audio_tracks} ) { | ||
| 194 | if ( $track->tc_target_track == $target ) { | ||
| 195 | $track->set_tc_target_track(-1); | ||
| 196 | last; | ||
| 197 | } | ||
| 198 | } | ||
| 199 | |||
| 200 | #-- now assign this target track | ||
| 201 | $audio_tracks->[$source]->set_tc_target_track($target); | ||
| 202 | } | ||
| 203 | |||
| 204 | #-- update selection | ||
| 205 | $check_button_group->update_selection; | ||
| 206 | |||
| 207 | #-- recalculate video bitrate | ||
| 208 | $title->calc_video_bitrate; | ||
| 209 | |||
| 210 | 1; | ||
| 211 | } | ||
| 212 | |||
| 213 | 1; |