~ubuntu-branches/ubuntu/maverick/qvamps/maverick

« back to all changes in this revision

Viewing changes to FpcMgr.pm

  • Committer: Bazaar Package Importer
  • Author(s): Claudio Moratti
  • Date: 2006-04-24 14:28:30 UTC
  • Revision ID: james.westby@ubuntu.com-20060424142830-mf5kk65fv3xc2ztz
Tags: upstream-0.97
ImportĀ upstreamĀ versionĀ 0.97

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# This file is part of qVamps.
 
2
#
 
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.
 
7
#
 
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.
 
12
#
 
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
 
16
 
 
17
 
 
18
use strict;
 
19
use warnings;
 
20
 
 
21
 
 
22
package FpcMgr;
 
23
use Qt;
 
24
use Qt::isa qw (Qt::Object);
 
25
use Qt::attributes qw (mtable_items title_combo audio_combo
 
26
                       subtitle_combo title_list_items ct);
 
27
use QVamps qw (search);
 
28
use MenuTableItems;
 
29
 
 
30
 
 
31
sub NEW
 
32
{
 
33
  my $this             = shift;
 
34
  my $parent           = shift;
 
35
  my $name             = shift;
 
36
  my $title_combo      = shift;
 
37
  my $audio_combo      = shift;
 
38
  my $subtitle_combo   = shift;
 
39
  my $title_list_items = shift;
 
40
  my $mtable_items     = shift;
 
41
 
 
42
  $this -> SUPER::NEW ($parent, $name);
 
43
 
 
44
  title_combo      = $title_combo;
 
45
  audio_combo      = $audio_combo;
 
46
  subtitle_combo   = $subtitle_combo;
 
47
  title_list_items = $title_list_items;
 
48
  mtable_items     = $mtable_items;
 
49
}
 
50
 
 
51
 
 
52
sub DESTROY
 
53
{
 
54
  parent () -> removeChild (this);
 
55
 
 
56
  ct               = 0;
 
57
  mtable_items     = undef;
 
58
  title_list_items = undef;
 
59
  subtitle_combo   = undef;
 
60
  audio_combo      = undef;
 
61
  title_combo      = undef;
 
62
 
 
63
  SUPER -> DESTROY ();
 
64
}
 
65
 
 
66
 
 
67
sub update_title
 
68
{
 
69
  my $nttn            = 0;
 
70
  my $title_combo     = title_combo;
 
71
  my $ttn             = $title_combo -> currentText ();
 
72
  my $selected_titles = title_list_items -> selected_titles ();
 
73
 
 
74
  # wipe out all combo box items
 
75
  $title_combo -> clear ();
 
76
  ct = 0;
 
77
 
 
78
  if (@{$selected_titles})
 
79
  {
 
80
    # list of selected titles not empty
 
81
    # --> create combo box items and set new title number to first in list
 
82
    $title_combo -> insertStringList ($selected_titles);
 
83
    $nttn = $title_combo -> currentText ();
 
84
    ct    = $nttn;
 
85
 
 
86
    if ($ttn)
 
87
    {
 
88
      # we had a title selected --> search in titles selected now
 
89
      my $i = search ($selected_titles, $ttn);
 
90
 
 
91
      unless ($i < 0)
 
92
      {
 
93
        # title still selected --> restore combo box selection
 
94
        $title_combo -> setCurrentItem ($i);
 
95
        ct = $ttn;
 
96
 
 
97
        # As user may have changed the title's audio and subtitle selection,
 
98
        # we need to update the audio and subtitle combo boxes. Even though
 
99
        # the title is still selected. Since the currently selected audio
 
100
        # and subtitle stream should be preserved in this case, returning
 
101
        # the title as negative number here indicates this situation.
 
102
        $nttn = -$ttn;
 
103
      }
 
104
    }
 
105
  }
 
106
 
 
107
  # adjust width of combo box
 
108
  adjust_combo_width ($title_combo);
 
109
 
 
110
  return $nttn;
 
111
}
 
112
 
 
113
 
 
114
sub update_audio
 
115
{
 
116
  my $ttn = shift;
 
117
 
 
118
  my $item;
 
119
  my $audio_combo = audio_combo;
 
120
 
 
121
  if ($ttn < 0)
 
122
  {
 
123
    $ttn  = -$ttn;
 
124
    $item = $audio_combo -> currentText ();
 
125
  }
 
126
 
 
127
  $audio_combo -> clear ();
 
128
 
 
129
  if ($ttn)
 
130
  {
 
131
    my $i;
 
132
    my $item_hash = mtable_items -> make_audio_item_hash ($ttn);
 
133
    my @streams   = sort { $a <=> $b } keys %{$item_hash};
 
134
    my @item_list = map $item_hash -> {$_}, @streams;
 
135
 
 
136
    if ($item)
 
137
    {
 
138
      $i = -1;
 
139
 
 
140
      for (my $j = 0; $j < @item_list; $j++)
 
141
      {
 
142
        if ($item eq $item_list [$j])
 
143
        {
 
144
          $i = $j;
 
145
          last;
 
146
        }
 
147
      }
 
148
    }
 
149
    else
 
150
    {
 
151
      $i = search (\@streams, mtable_items -> default_audio_stream ());
 
152
    }
 
153
 
 
154
    $audio_combo -> insertStringList (\@item_list);
 
155
    $audio_combo -> setCurrentItem ($i) unless ($i < 0);
 
156
  }
 
157
 
 
158
  adjust_combo_width ($audio_combo);
 
159
}
 
160
 
 
161
 
 
162
sub update_subtitle
 
163
{
 
164
  my $ttn = shift;
 
165
 
 
166
  my $item;
 
167
  my $subtitle_combo = subtitle_combo;
 
168
 
 
169
  if ($ttn < 0)
 
170
  {
 
171
    $ttn  = -$ttn;
 
172
    $item = $subtitle_combo -> currentText ();
 
173
  }
 
174
 
 
175
  $subtitle_combo -> clear ();
 
176
 
 
177
  if ($ttn)
 
178
  {
 
179
    my $item_hash = mtable_items -> make_subtitle_item_hash ($ttn);
 
180
    my @streams   = sort { $a <=> $b } keys %{$item_hash};
 
181
    my @item_list = map $item_hash -> {$_}, @streams;
 
182
 
 
183
    $subtitle_combo -> insertStringList (\@item_list);
 
184
 
 
185
    if ($item)
 
186
    {
 
187
      for (my $i = 0; $i < @item_list; $i++)
 
188
      {
 
189
        if ($item eq $item_list [$i])
 
190
        {
 
191
          $subtitle_combo -> setCurrentItem ($i);
 
192
          last;
 
193
        }
 
194
      }
 
195
    }
 
196
  }
 
197
 
 
198
  adjust_combo_width ($subtitle_combo);
 
199
}
 
200
 
 
201
 
 
202
sub adjust_combo_width
 
203
{
 
204
  my $combo = shift;
 
205
 
 
206
  $combo -> setFont ($combo -> font ());
 
207
  $combo -> updateGeometry ();
 
208
}
 
209
 
 
210
 
 
211
sub update
 
212
{
 
213
  my $ttn = update_title ();
 
214
 
 
215
  update_audio ($ttn);
 
216
  update_subtitle ($ttn);
 
217
}
 
218
 
 
219
 
 
220
sub title_changed
 
221
{
 
222
  my $ttn = shift;
 
223
 
 
224
  unless ($ttn == ct)
 
225
  {
 
226
    ct = $ttn;
 
227
    update_audio ($ttn);
 
228
    update_subtitle ($ttn);
 
229
  }
 
230
}
 
231
 
 
232
 
 
233
sub title_nr
 
234
{
 
235
  my $title_combo = title_combo;
 
236
 
 
237
  return 0 unless ($title_combo -> count ());
 
238
 
 
239
  return $title_combo -> currentItem () + 1;
 
240
}
 
241
 
 
242
 
 
243
sub audio_stream
 
244
{
 
245
  return audio_combo -> currentItem ();
 
246
}
 
247
 
 
248
 
 
249
sub subtitle_stream
 
250
{
 
251
  return audio_combo -> currentItem () - 1;
 
252
}
 
253
 
 
254
 
 
255
1;