]> git.sesse.net Git - vlc/blob - modules/gui/qt4/input_manager.cpp
Remove useless binary and with CONFIG_ITEM
[vlc] / modules / gui / qt4 / input_manager.cpp
1 /*****************************************************************************
2  * input_manager.cpp : Manage an input and interact with its GUI elements
3  ****************************************************************************
4  * Copyright (C) 2006-2008 the VideoLAN team
5  * $Id$
6  *
7  * Authors: ClĂ©ment Stenac <zorglub@videolan.org>
8  *          Ilkka Ollakka  <ileoo@videolan.org>
9  *          Jean-Baptiste <jb@videolan.org>
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24  *****************************************************************************/
25
26 #define __STDC_FORMAT_MACROS 1
27
28 #ifdef HAVE_CONFIG_H
29 # include "config.h"
30 #endif
31
32 #include "input_manager.hpp"
33 #include <vlc_keys.h>
34 #include <vlc_url.h>
35 #include <vlc_strings.h>
36 #include <vlc_aout.h>
37
38 #include <QApplication>
39
40 #include <assert.h>
41
42 static int ItemChanged( vlc_object_t *, const char *,
43                         vlc_value_t, vlc_value_t, void * );
44 static int LeafToParent( vlc_object_t *, const char *,
45                         vlc_value_t, vlc_value_t, void * );
46 static int PLItemChanged( vlc_object_t *, const char *,
47                         vlc_value_t, vlc_value_t, void * );
48 static int PLItemAppended( vlc_object_t *, const char *,
49                         vlc_value_t, vlc_value_t, void * );
50 static int PLItemRemoved( vlc_object_t *, const char *,
51                         vlc_value_t, vlc_value_t, void * );
52 static int VolumeChanged( vlc_object_t *, const char *,
53                         vlc_value_t, vlc_value_t, void * );
54 static int SoundMuteChanged( vlc_object_t *, const char *,
55                         vlc_value_t, vlc_value_t, void * );
56
57 static int RandomChanged( vlc_object_t *, const char *,
58                         vlc_value_t, vlc_value_t, void * );
59 static int LoopChanged( vlc_object_t *, const char *,
60                         vlc_value_t, vlc_value_t, void * );
61 static int RepeatChanged( vlc_object_t *, const char *,
62                         vlc_value_t, vlc_value_t, void * );
63
64
65 static int InputEvent( vlc_object_t *, const char *,
66                        vlc_value_t, vlc_value_t, void * );
67 static int VbiEvent( vlc_object_t *, const char *,
68                      vlc_value_t, vlc_value_t, void * );
69
70
71 /**********************************************************************
72  * InputManager implementation
73  **********************************************************************
74  * The Input Manager can be the main one around the playlist
75  * But can also be used for VLM dialog or similar
76  **********************************************************************/
77
78 InputManager::InputManager( QObject *parent, intf_thread_t *_p_intf) :
79                            QObject( parent ), p_intf( _p_intf )
80 {
81     i_old_playing_status = END_S;
82     oldName      = "";
83     artUrl       = "";
84     p_input      = NULL;
85     p_input_vbi  = NULL;
86     f_rate       = 0.;
87     p_item       = NULL;
88     b_video      = false;
89     timeA        = 0;
90     timeB        = 0;
91     f_cache      = -1.; /* impossible initial value, different from all */
92 }
93
94 InputManager::~InputManager()
95 {
96     delInput();
97 }
98
99 /* Define the Input used.
100    Add the callbacks on input
101    p_input is held once here */
102 void InputManager::setInput( input_thread_t *_p_input )
103 {
104     delInput();
105     p_input = _p_input;
106     if( p_input && !( p_input->b_dead || !vlc_object_alive (p_input) ) )
107     {
108         msg_Dbg( p_intf, "IM: Setting an input" );
109         vlc_object_hold( p_input );
110         addCallbacks();
111         UpdateStatus();
112         UpdateName();
113         UpdateArt();
114         UpdateTeletext();
115         UpdateNavigation();
116         UpdateVout();
117
118         p_item = input_GetItem( p_input );
119         emit rateChanged( var_GetFloat( p_input, "rate" ) );
120     }
121     else
122     {
123         p_input = NULL;
124         p_item = NULL;
125         assert( !p_input_vbi );
126         emit rateChanged( var_InheritFloat( p_intf, "rate" ) );
127     }
128 }
129
130 /* delete Input if it ever existed.
131    Delete the callbacls on input
132    p_input is released once here */
133 void InputManager::delInput()
134 {
135     if( !p_input ) return;
136     msg_Dbg( p_intf, "IM: Deleting the input" );
137
138     delCallbacks();
139     i_old_playing_status = END_S;
140     p_item               = NULL;
141     oldName              = "";
142     artUrl               = "";
143     b_video              = false;
144     timeA                = 0;
145     timeB                = 0;
146     f_rate               = 0. ;
147
148     if( p_input_vbi )
149     {
150         vlc_object_release( p_input_vbi );
151         p_input_vbi = NULL;
152     }
153
154     vlc_object_release( p_input );
155     p_input = NULL;
156
157     emit positionUpdated( -1.0, 0 ,0 );
158     emit rateChanged( var_InheritFloat( p_intf, "rate" ) );
159     emit nameChanged( "" );
160     emit chapterChanged( 0 );
161     emit titleChanged( 0 );
162     emit playingStatusChanged( END_S );
163
164     emit teletextPossible( false );
165     emit AtoBchanged( false, false );
166     emit voutChanged( false );
167     emit voutListChanged( NULL, 0 );
168
169     /* Reset all InfoPanels but stats */
170     emit artChanged( NULL );
171     emit infoChanged( NULL );
172     emit currentMetaChanged( (input_item_t *)NULL );
173
174     emit encryptionChanged( false );
175     emit recordingStateChanged( false );
176
177     emit cachingChanged( 1 );
178 }
179
180 /* Convert the event from the callbacks in actions */
181 void InputManager::customEvent( QEvent *event )
182 {
183     int i_type = event->type();
184     IMEvent *ple = static_cast<IMEvent *>(event);
185
186     if( i_type == ItemChanged_Type )
187         UpdateMeta( ple->p_item );
188
189     if( !hasInput() )
190         return;
191
192     /* Actions */
193     switch( i_type )
194     {
195     case PositionUpdate_Type:
196         UpdatePosition();
197         break;
198     case StatisticsUpdate_Type:
199         UpdateStats();
200         break;
201     case ItemChanged_Type:
202         /* Ignore ItemChanged_Type event that does not apply to our input */
203         if( p_item == ple->p_item )
204         {
205             UpdateStatus();
206             // UpdateName();
207             UpdateArt();
208             /* Update duration of file */
209         }
210         break;
211     case ItemStateChanged_Type:
212         // TODO: Fusion with above state
213         UpdateStatus();
214         // UpdateName();
215         // UpdateNavigation(); This shouldn't be useful now
216         // UpdateTeletext(); Same
217         break;
218     case NameChanged_Type:
219         UpdateName();
220         break;
221     case MetaChanged_Type:
222         UpdateMeta();
223         UpdateName(); /* Needed for NowPlaying */
224         UpdateArt(); /* Art is part of meta in the core */
225         break;
226     case InfoChanged_Type:
227         UpdateInfo();
228         break;
229     case ItemTitleChanged_Type:
230         UpdateNavigation();
231         UpdateName(); /* Display the name of the Chapter, if exists */
232         break;
233     case ItemRateChanged_Type:
234         UpdateRate();
235         break;
236     case ItemEsChanged_Type:
237         UpdateTeletext();
238         // We don't do anything ES related. Why ?
239         break;
240     case ItemTeletextChanged_Type:
241         UpdateTeletext();
242         break;
243     case InterfaceVoutUpdate_Type:
244         UpdateVout();
245         break;
246     case SynchroChanged_Type:
247         emit synchroChanged();
248         break;
249     case CachingEvent_Type:
250         UpdateCaching();
251         break;
252     case BookmarksChanged_Type:
253         emit bookmarksChanged();
254         break;
255     case InterfaceAoutUpdate_Type:
256         UpdateAout();
257         break;
258     case RecordingEvent_Type:
259         UpdateRecord();
260         break;
261     case ProgramChanged_Type:
262         UpdateProgramEvent();
263         break;
264     case EPGEvent_Type:
265         UpdateEPG();
266         break;
267     default:
268         msg_Warn( p_intf, "This shouldn't happen: %i", i_type );
269         assert(0);
270     }
271 }
272
273 /* Add the callbacks on Input. Self explanatory */
274 inline void InputManager::addCallbacks()
275 {
276     var_AddCallback( p_input, "intf-event", InputEvent, this );
277 }
278
279 /* Delete the callbacks on Input. Self explanatory */
280 inline void InputManager::delCallbacks()
281 {
282     var_DelCallback( p_input, "intf-event", InputEvent, this );
283 }
284
285 /* Static callbacks for IM */
286 static int ItemChanged( vlc_object_t *p_this, const char *psz_var,
287                         vlc_value_t oldval, vlc_value_t newval, void *param )
288 {
289     VLC_UNUSED( p_this ); VLC_UNUSED( psz_var ); VLC_UNUSED( oldval );
290
291     InputManager *im = (InputManager*)param;
292     input_item_t *p_item = static_cast<input_item_t *>(newval.p_address);
293
294     IMEvent *event = new IMEvent( ItemChanged_Type, p_item );
295     QApplication::postEvent( im, event );
296     return VLC_SUCCESS;
297 }
298
299 static int InputEvent( vlc_object_t *p_this, const char *,
300                        vlc_value_t, vlc_value_t newval, void *param )
301 {
302     VLC_UNUSED( p_this );
303
304     InputManager *im = (InputManager*)param;
305     IMEvent *event;
306
307     switch( newval.i_int )
308     {
309     case INPUT_EVENT_STATE:
310         event = new IMEvent( ItemStateChanged_Type );
311         break;
312     case INPUT_EVENT_RATE:
313         event = new IMEvent( ItemRateChanged_Type );
314         break;
315     case INPUT_EVENT_POSITION:
316     //case INPUT_EVENT_LENGTH:
317         event = new IMEvent( PositionUpdate_Type );
318         break;
319
320     case INPUT_EVENT_TITLE:
321     case INPUT_EVENT_CHAPTER:
322         event = new IMEvent( ItemTitleChanged_Type );
323         break;
324
325     case INPUT_EVENT_ES:
326         event = new IMEvent( ItemEsChanged_Type );
327         break;
328     case INPUT_EVENT_TELETEXT:
329         event = new IMEvent( ItemTeletextChanged_Type );
330         break;
331
332     case INPUT_EVENT_STATISTICS:
333         event = new IMEvent( StatisticsUpdate_Type );
334         break;
335
336     case INPUT_EVENT_VOUT:
337         event = new IMEvent( InterfaceVoutUpdate_Type );
338         break;
339     case INPUT_EVENT_AOUT:
340         event = new IMEvent( InterfaceAoutUpdate_Type );
341         break;
342
343     case INPUT_EVENT_ITEM_META: /* Codec MetaData + Art */
344         event = new IMEvent( MetaChanged_Type );
345         break;
346     case INPUT_EVENT_ITEM_INFO: /* Codec Info */
347         event = new IMEvent( InfoChanged_Type );
348         break;
349     case INPUT_EVENT_ITEM_NAME:
350         event = new IMEvent( NameChanged_Type );
351         break;
352
353     case INPUT_EVENT_AUDIO_DELAY:
354     case INPUT_EVENT_SUBTITLE_DELAY:
355         event = new IMEvent( SynchroChanged_Type );
356         break;
357
358     case INPUT_EVENT_CACHE:
359         event = new IMEvent( CachingEvent_Type );
360         break;
361
362     case INPUT_EVENT_BOOKMARK:
363         event = new IMEvent( BookmarksChanged_Type );
364         break;
365
366     case INPUT_EVENT_RECORD:
367         event = new IMEvent( RecordingEvent_Type );
368         break;
369
370     case INPUT_EVENT_PROGRAM:
371         /* This is for PID changes */
372         event = new IMEvent( ProgramChanged_Type );
373         break;
374
375     case INPUT_EVENT_ITEM_EPG:
376         /* EPG data changed */
377         event = new IMEvent( EPGEvent_Type );
378         break;
379
380     case INPUT_EVENT_SIGNAL:
381         /* This is for capture-card signals */
382         /* event = new IMEvent( SignalChanged_Type );
383         break; */
384     default:
385         event = NULL;
386         break;
387     }
388
389     if( event )
390         QApplication::postEvent( im, event );
391     return VLC_SUCCESS;
392 }
393
394 static int VbiEvent( vlc_object_t *, const char *,
395                      vlc_value_t, vlc_value_t, void *param )
396 {
397     InputManager *im = (InputManager*)param;
398     IMEvent *event = new IMEvent( ItemTeletextChanged_Type );
399
400     QApplication::postEvent( im, event );
401     return VLC_SUCCESS;
402 }
403
404 void InputManager::UpdatePosition()
405 {
406     /* Update position */
407     int i_length;
408     int64_t i_time;
409     float f_pos;
410     i_length = var_GetTime(  p_input , "length" ) / 1000000;
411     i_time = var_GetTime(  p_input , "time");
412     f_pos = var_GetFloat(  p_input , "position" );
413     emit positionUpdated( f_pos, i_time, i_length );
414 }
415
416 void InputManager::UpdateNavigation()
417 {
418     /* Update navigation status */
419     vlc_value_t val; val.i_int = 0;
420     vlc_value_t val2; val2.i_int = 0;
421
422     if( hasInput() )
423         var_Change( p_input, "title", VLC_VAR_CHOICESCOUNT, &val, NULL );
424
425     if( val.i_int > 0 )
426     {
427         emit titleChanged( true );
428         msg_Dbg( p_intf, "Title %"PRId64, val.i_int );
429         /* p_input != NULL since val.i_int != 0 */
430         var_Change( p_input, "chapter", VLC_VAR_CHOICESCOUNT, &val2, NULL );
431         emit chapterChanged( (val2.i_int > 1) || ( val2.i_int > 0 && val.i_int > 1 ) );
432         msg_Dbg( p_intf, "Chapter: %"PRId64, val2.i_int );
433     }
434     else
435         emit titleChanged( false );
436 }
437
438 void InputManager::UpdateStatus()
439 {
440     /* Update playing status */
441     int state = var_GetInteger( p_input, "state" );
442     if( i_old_playing_status != state )
443     {
444         i_old_playing_status = state;
445         emit playingStatusChanged( state );
446     }
447 }
448
449 void InputManager::UpdateRate()
450 {
451     /* Update Rate */
452     float f_new_rate = var_GetFloat( p_input, "rate" );
453     if( f_new_rate != f_rate )
454     {
455         f_rate = f_new_rate;
456         /* Update rate */
457         emit rateChanged( f_rate );
458     }
459 }
460
461 void InputManager::UpdateName()
462 {
463     /* Update text, name and nowplaying */
464     QString name;
465
466     /* Try to get the nowplaying */
467     char *format = var_InheritString( p_intf, "input-title-format" );
468     char *formated = str_format_meta( p_input, format );
469     free( format );
470     name = qfu(formated);
471     free( formated );
472
473     /* If we have Nothing */
474     if( name.isEmpty() )
475     {
476         char *uri = input_item_GetURI( input_GetItem( p_input ) );
477         char *file = uri ? strrchr( uri, '/' ) : NULL;
478         if( file != NULL )
479         {
480             decode_URI( ++file );
481             name = qfu(file);
482         }
483         else
484             name = qfu(uri);
485         free( uri );
486     }
487
488     name = name.trimmed();
489
490     if( oldName != name )
491     {
492         emit nameChanged( name );
493         oldName = name;
494     }
495 }
496
497 int InputManager::playingStatus()
498 {
499     return i_old_playing_status;
500 }
501
502 bool InputManager::hasAudio()
503 {
504     if( hasInput() )
505     {
506         vlc_value_t val;
507         var_Change( p_input, "audio-es", VLC_VAR_CHOICESCOUNT, &val, NULL );
508         return val.i_int > 0;
509     }
510     return false;
511 }
512
513 bool InputManager::hasVisualisation()
514 {
515     if( !p_input )
516         return false;
517
518     aout_instance_t *aout = input_GetAout( p_input );
519     if( !aout )
520         return false;
521
522     char *visual = var_InheritString( aout, "visual" );
523     vlc_object_release( aout );
524
525     if( !visual )
526         return false;
527
528     free( visual );
529     return true;
530 }
531
532 void InputManager::UpdateTeletext()
533 {
534     if( hasInput() )
535     {
536         const bool b_enabled = var_CountChoices( p_input, "teletext-es" ) > 0;
537         const int i_teletext_es = var_GetInteger( p_input, "teletext-es" );
538
539         /* Teletext is possible. Show the buttons */
540         emit teletextPossible( b_enabled );
541
542         /* If Teletext is selected */
543         if( b_enabled && i_teletext_es >= 0 )
544         {
545             /* Then, find the current page */
546             int i_page = 100;
547             bool b_transparent = false;
548
549             if( p_input_vbi )
550             {
551                 var_DelCallback( p_input_vbi, "vbi-page", VbiEvent, this );
552                 vlc_object_release( p_input_vbi );
553             }
554
555             if( input_GetEsObjects( p_input, i_teletext_es, &p_input_vbi, NULL, NULL ) )
556                 p_input_vbi = NULL;
557
558             if( p_input_vbi )
559             {
560                 /* This callback is not remove explicitly, but interfaces
561                  * are guaranted to outlive input */
562                 var_AddCallback( p_input_vbi, "vbi-page", VbiEvent, this );
563
564                 i_page = var_GetInteger( p_input_vbi, "vbi-page" );
565                 b_transparent = !var_GetBool( p_input_vbi, "vbi-opaque" );
566             }
567             emit newTelexPageSet( i_page );
568             emit teletextTransparencyActivated( b_transparent );
569
570         }
571         emit teletextActivated( b_enabled && i_teletext_es >= 0 );
572     }
573     else
574     {
575         emit teletextActivated( false );
576         emit teletextPossible( false );
577     }
578 }
579
580 void InputManager::UpdateEPG()
581 {
582     if( hasInput() )
583     {
584        emit epgChanged();
585     }
586 }
587
588 void InputManager::UpdateVout()
589 {
590     if( hasInput() )
591     {
592         /* Get current vout lists from input */
593         size_t i_vout;
594         vout_thread_t **pp_vout;
595         if( input_Control( p_input, INPUT_GET_VOUTS, &pp_vout, &i_vout ) )
596         {
597             i_vout = 0;
598             pp_vout = NULL;
599         }
600
601         /* */
602         emit voutListChanged( pp_vout, i_vout );
603
604         /* */
605         bool b_old_video = b_video;
606         b_video = i_vout > 0;
607         if( !!b_old_video != !!b_video )
608             emit voutChanged( b_video );
609
610         /* Release the vout list */
611         for( size_t i = 0; i < i_vout; i++ )
612             vlc_object_release( (vlc_object_t*)pp_vout[i] );
613         free( pp_vout );
614     }
615 }
616 void InputManager::UpdateAout()
617 {
618     if( hasInput() )
619     {
620         /* TODO */
621     }
622 }
623 void InputManager::UpdateCaching()
624 {
625     if(!hasInput()) return;
626
627     float f_newCache = var_GetFloat ( p_input, "cache" );
628     if( f_newCache != f_cache )
629     {
630         f_cache = f_newCache;
631         /* Update cache */
632         emit cachingChanged( f_cache );
633     }
634 }
635
636 void InputManager::requestArtUpdate()
637 {
638     if( hasInput() )
639     {
640         playlist_AskForArtEnqueue( pl_Get(p_intf), input_GetItem( p_input ) );
641     }
642     else
643     {
644         /* No input will signal the cover art to update,
645          * let's do it ourself */
646         UpdateArt();
647     }
648 }
649
650 const QString InputManager::decodeArtURL( input_item_t *p_item )
651 {
652     assert( p_item );
653
654     char *psz_art = input_item_GetArtURL( p_item );
655     if( psz_art )
656     {
657         char *psz = make_path( psz_art );
658         free( psz_art );
659         psz_art = psz;
660     }
661
662 #if 0
663     /* Taglib seems to define a attachment://, It won't work yet */
664     url = url.replace( "attachment://", "" );
665 #endif
666
667     QString path = qfu( psz_art ? psz_art : "" );
668     free( psz_art );
669     return path;
670 }
671
672 void InputManager::UpdateArt()
673 {
674     QString url;
675
676     if( hasInput() )
677         url = decodeArtURL( input_GetItem( p_input ) );
678
679     /* the art hasn't changed, no need to update */
680     if(artUrl == url)
681         return;
682
683     /* Update Art meta */
684     artUrl = url;
685     emit artChanged( artUrl );
686 }
687
688 inline void InputManager::UpdateStats()
689 {
690     emit statisticsUpdated( input_GetItem( p_input ) );
691 }
692
693 inline void InputManager::UpdateMeta( input_item_t *p_item )
694 {
695     emit metaChanged( p_item );
696 }
697
698 inline void InputManager::UpdateMeta()
699 {
700     emit currentMetaChanged( input_GetItem( p_input ) );
701 }
702
703 inline void InputManager::UpdateInfo()
704 {
705     emit infoChanged( input_GetItem( p_input ) );
706 }
707
708 void InputManager::UpdateRecord()
709 {
710     if( hasInput() )
711     {
712         emit recordingStateChanged( var_GetBool( p_input, "record" ) );
713     }
714 }
715
716 void InputManager::UpdateProgramEvent()
717 {
718     if( hasInput() )
719     {
720         bool b_scrambled = var_GetBool( p_input, "program-scrambled" );
721         emit encryptionChanged( b_scrambled );
722     }
723 }
724
725 /* User update of the slider */
726 void InputManager::sliderUpdate( float new_pos )
727 {
728     if( hasInput() )
729         var_SetFloat( p_input, "position", new_pos );
730     emit seekRequested( new_pos );
731 }
732
733 /* User togglePlayPause */
734 void InputManager::togglePlayPause()
735 {
736     if( hasInput() )
737     {
738         int state = var_GetInteger( p_input, "state" );
739         state = ( state != PLAYING_S ) ? PLAYING_S : PAUSE_S;
740         var_SetInteger( p_input, "state", state );
741     }
742 }
743
744 void InputManager::sectionPrev()
745 {
746     if( hasInput() )
747     {
748         int i_type = var_Type( p_input, "next-chapter" );
749         var_TriggerCallback( p_input, (i_type & VLC_VAR_TYPE) != 0 ?
750                              "prev-chapter":"prev-title" );
751     }
752 }
753
754 void InputManager::sectionNext()
755 {
756     if( hasInput() )
757     {
758         int i_type = var_Type( p_input, "next-chapter" );
759         var_TriggerCallback( p_input, (i_type & VLC_VAR_TYPE) != 0 ?
760                              "next-chapter":"next-title" );
761     }
762 }
763
764 void InputManager::sectionMenu()
765 {
766     if( hasInput() )
767     {
768         vlc_value_t val, text;
769
770         if( var_Change( p_input, "title  0", VLC_VAR_GETLIST, &val, &text ) < 0 )
771             return;
772
773         /* XXX is it "Root" or "Title" we want here ?" (set 0 by default) */
774         int root = 0;
775         for( int i = 0; i < val.p_list->i_count; i++ )
776         {
777             if( !strcmp( text.p_list->p_values[i].psz_string, "Title" ) )
778                 root = i;
779         }
780         var_FreeList( &val, &text );
781
782         var_SetInteger( p_input, "title  0", root );
783     }
784 }
785
786 /*
787  *  Teletext Functions
788  */
789
790 /* Set a new Teletext Page */
791 void InputManager::telexSetPage( int page )
792 {
793     if( hasInput() && p_input_vbi )
794     {
795         const int i_teletext_es = var_GetInteger( p_input, "teletext-es" );
796
797         if( i_teletext_es >= 0 )
798         {
799             var_SetInteger( p_input_vbi, "vbi-page", page );
800             emit newTelexPageSet( page );
801         }
802     }
803 }
804
805 /* Set the transparency on teletext */
806 void InputManager::telexSetTransparency( bool b_transparentTelextext )
807 {
808     if( hasInput() && p_input_vbi )
809     {
810         var_SetBool( p_input_vbi, "vbi-opaque", !b_transparentTelextext );
811         emit teletextTransparencyActivated( b_transparentTelextext );
812     }
813 }
814
815 void InputManager::activateTeletext( bool b_enable )
816 {
817     vlc_value_t list;
818     vlc_value_t text;
819     if( hasInput() && !var_Change( p_input, "teletext-es", VLC_VAR_GETLIST, &list, &text ) )
820     {
821         if( list.p_list->i_count > 0 )
822         {
823             /* Prefer the page 100 if it is present */
824             int i;
825             for( i = 0; i < text.p_list->i_count; i++ )
826             {
827                 /* The description is the page number as a string */
828                 const char *psz_page = text.p_list->p_values[i].psz_string;
829                 if( psz_page && !strcmp( psz_page, "100" ) )
830                     break;
831             }
832             if( i >= list.p_list->i_count )
833                 i = 0;
834             var_SetInteger( p_input, "spu-es", b_enable ? list.p_list->p_values[i].i_int : -1 );
835         }
836         var_FreeList( &list, &text );
837     }
838 }
839
840 void InputManager::reverse()
841 {
842     if( hasInput() )
843     {
844         float f_rate = var_GetFloat( p_input, "rate" );
845         var_SetFloat( p_input, "rate", -f_rate );
846     }
847 }
848
849 void InputManager::slower()
850 {
851     var_TriggerCallback( THEPL, "rate-slower" );
852 }
853
854 void InputManager::faster()
855 {
856     var_TriggerCallback( THEPL, "rate-faster" );
857 }
858
859 void InputManager::littlefaster()
860 {
861     var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_RATE_FASTER_FINE );
862 }
863
864 void InputManager::littleslower()
865 {
866     var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_RATE_SLOWER_FINE );
867 }
868
869 void InputManager::normalRate()
870 {
871     var_SetFloat( THEPL, "rate", 1. );
872 }
873
874 void InputManager::setRate( int new_rate )
875 {
876     var_SetFloat( THEPL, "rate",
877                  (float)INPUT_RATE_DEFAULT / (float)new_rate );
878 }
879
880 void InputManager::jumpFwd()
881 {
882     int i_interval = var_InheritInteger( p_input, "short-jump-size" );
883     if( i_interval > 0 )
884     {
885         mtime_t val = (mtime_t)(i_interval) * 1000000L;
886         var_SetTime( p_input, "time-offset", val );
887     }
888 }
889
890 void InputManager::jumpBwd()
891 {
892     int i_interval = var_InheritInteger( p_input, "short-jump-size" );
893     if( i_interval > 0 )
894     {
895         mtime_t val = -1 *(mtime_t)(i_interval) * 1000000L;
896         var_SetTime( p_input, "time-offset", val );
897     }
898 }
899
900 void InputManager::setAtoB()
901 {
902     if( !timeA )
903     {
904         timeA = var_GetTime( THEMIM->getInput(), "time"  );
905     }
906     else if( !timeB )
907     {
908         timeB = var_GetTime( THEMIM->getInput(), "time"  );
909         var_SetTime( THEMIM->getInput(), "time" , timeA );
910         CONNECT( this, positionUpdated( float, int64_t, int ),
911                  this, AtoBLoop( float, int64_t, int ) );
912     }
913     else
914     {
915         timeA = 0;
916         timeB = 0;
917         disconnect( this, SIGNAL( positionUpdated( float, int64_t, int ) ),
918                     this, SLOT( AtoBLoop( float, int64_t, int ) ) );
919     }
920     emit AtoBchanged( (timeA != 0 ), (timeB != 0 ) );
921 }
922
923 /* Function called regularly when in an AtoB loop */
924 void InputManager::AtoBLoop( float, int64_t i_time, int )
925 {
926     if( timeB )
927     {
928         if( i_time >= timeB || i_time < timeA )
929             var_SetTime( THEMIM->getInput(), "time" , timeA );
930     }
931 }
932
933 /**********************************************************************
934  * MainInputManager implementation. Wrap an input manager and
935  * take care of updating the main playlist input.
936  * Used in the main playlist Dialog
937  **********************************************************************/
938
939 MainInputManager::MainInputManager( intf_thread_t *_p_intf )
940                  : QObject(NULL), p_intf( _p_intf )
941 {
942     p_input = NULL;
943     im = new InputManager( this, p_intf );
944
945     var_AddCallback( THEPL, "item-change", ItemChanged, im );
946     var_AddCallback( THEPL, "item-current", PLItemChanged, this );
947     var_AddCallback( THEPL, "activity", PLItemChanged, this );
948     var_AddCallback( THEPL, "leaf-to-parent", LeafToParent, this );
949     var_AddCallback( THEPL, "playlist-item-append", PLItemAppended, this );
950     var_AddCallback( THEPL, "playlist-item-deleted", PLItemRemoved, this );
951     var_AddCallback( THEPL, "random", RandomChanged, this );
952     var_AddCallback( THEPL, "repeat", RepeatChanged, this );
953     var_AddCallback( THEPL, "loop", LoopChanged, this );
954
955     var_AddCallback( THEPL, "volume", VolumeChanged, this );
956     var_AddCallback( THEPL, "mute", SoundMuteChanged, this );
957
958     /* Warn our embedded IM about input changes */
959     DCONNECT( this, inputChanged( input_thread_t * ),
960               im, setInput( input_thread_t * ) );
961
962 }
963
964 MainInputManager::~MainInputManager()
965 {
966     if( p_input )
967     {
968        emit inputChanged( NULL );
969        var_DelCallback( p_input, "state", PLItemChanged, this );
970        vlc_object_release( p_input );
971     }
972
973     var_DelCallback( THEPL, "volume", VolumeChanged, this );
974     var_DelCallback( THEPL, "mute", SoundMuteChanged, this );
975
976     var_DelCallback( THEPL, "activity", PLItemChanged, this );
977     var_DelCallback( THEPL, "item-change", ItemChanged, im );
978     var_DelCallback( THEPL, "leaf-to-parent", LeafToParent, this );
979
980     var_DelCallback( THEPL, "item-current", PLItemChanged, this );
981     var_DelCallback( THEPL, "playlist-item-append", PLItemAppended, this );
982     var_DelCallback( THEPL, "playlist-item-deleted", PLItemRemoved, this );
983     var_DelCallback( THEPL, "random", RandomChanged, this );
984     var_DelCallback( THEPL, "repeat", RepeatChanged, this );
985     var_DelCallback( THEPL, "loop", LoopChanged, this );
986
987 }
988
989 vout_thread_t* MainInputManager::getVout()
990 {
991     return p_input ? input_GetVout( p_input ) : NULL;
992 }
993
994 aout_instance_t * MainInputManager::getAout()
995 {
996     return p_input ? input_GetAout( p_input ) : NULL;
997 }
998
999 void MainInputManager::customEvent( QEvent *event )
1000 {
1001     int type = event->type();
1002
1003     PLEvent *plEv;
1004
1005     // msg_Dbg( p_intf, "New MainIM Event of type: %i", type );
1006     switch( type )
1007     {
1008     case VolumeChanged_Type:
1009         emit volumeChanged();
1010         return;
1011     case SoundMuteChanged_Type:
1012         emit soundMuteChanged();
1013         return;
1014     case PLItemAppended_Type:
1015         plEv = static_cast<PLEvent*>( event );
1016         emit playlistItemAppended( plEv->i_item, plEv->i_parent );
1017         return;
1018     case PLItemRemoved_Type:
1019         plEv = static_cast<PLEvent*>( event );
1020         emit playlistItemRemoved( plEv->i_item );
1021         return;
1022     case RandomChanged_Type:
1023         emit randomChanged( var_GetBool( THEPL, "random" ) );
1024         return;
1025     case LoopChanged_Type:
1026     case RepeatChanged_Type:
1027         notifyRepeatLoop();
1028         return;
1029     case LeafToParent_Type:
1030         plEv = static_cast<PLEvent*>( event );
1031         emit leafBecameParent( plEv->i_item );
1032         return;
1033     default:
1034         if( type != ItemChanged_Type ) return;
1035     }
1036
1037     /* Should be PLItemChanged Event */
1038     if( !p_intf->p_sys->b_isDialogProvider )
1039     {
1040         if( p_input && ( p_input->b_dead || !vlc_object_alive (p_input) ) )
1041         {
1042             emit inputChanged( p_input );
1043             var_DelCallback( p_input, "state", PLItemChanged, this );
1044             vlc_object_release( p_input );
1045             p_input = NULL;
1046             return;
1047         }
1048
1049         if( !p_input )
1050         {
1051             p_input = playlist_CurrentInput(THEPL);
1052             if( p_input )
1053             {
1054                 var_AddCallback( p_input, "state", PLItemChanged, this );
1055                 emit inputChanged( p_input );
1056             }
1057         }
1058     }
1059     else
1060     {
1061         /* remove previous stored p_input */
1062         if( p_input )
1063         {
1064             vlc_object_release( p_input );
1065             p_input = NULL;
1066         }
1067         /* we are working as a dialogs provider */
1068         p_input = playlist_CurrentInput( pl_Get(p_intf) );
1069         if( p_input )
1070         {
1071             emit inputChanged( p_input );
1072         }
1073     }
1074 }
1075
1076 /* Playlist Control functions */
1077 void MainInputManager::stop()
1078 {
1079    playlist_Stop( THEPL );
1080 }
1081
1082 void MainInputManager::next()
1083 {
1084    playlist_Next( THEPL );
1085 }
1086
1087 void MainInputManager::prev()
1088 {
1089    playlist_Prev( THEPL );
1090 }
1091
1092 void MainInputManager::prevOrReset()
1093 {
1094     if( !p_input || var_GetTime(  p_input , "time") < 10000 )
1095         playlist_Prev( THEPL );
1096     else
1097         getIM()->sliderUpdate( 0.0 );
1098 }
1099
1100 void MainInputManager::togglePlayPause()
1101 {
1102     /* No input, play */
1103     if( !p_input )
1104         playlist_Play( THEPL );
1105     else
1106         getIM()->togglePlayPause();
1107 }
1108
1109 void MainInputManager::play()
1110 {
1111     /* No input, play */
1112     if( !p_input )
1113         playlist_Play( THEPL );
1114     else
1115     {
1116         if( PLAYING_S != var_GetInteger( p_input, "state" ) )
1117         {
1118             getIM()->togglePlayPause();
1119         }
1120     }
1121 }
1122
1123 void MainInputManager::pause()
1124 {
1125     if(p_input && PLAYING_S == var_GetInteger( p_input, "state" ) )
1126     {
1127         getIM()->togglePlayPause();
1128     }
1129 }
1130
1131 void MainInputManager::toggleRandom()
1132 {
1133     var_ToggleBool( THEPL, "random" );
1134 }
1135
1136 void MainInputManager::notifyRepeatLoop()
1137 {
1138     int i_value = var_GetBool( THEPL, "loop" ) * REPEAT_ALL
1139               + var_GetBool( THEPL, "repeat" ) * REPEAT_ONE;
1140
1141     emit repeatLoopChanged( i_value );
1142 }
1143
1144 void MainInputManager::loopRepeatLoopStatus()
1145 {
1146     /* Toggle Normal -> Loop -> Repeat -> Normal ... */
1147     if( var_GetBool( THEPL, "repeat" ) )
1148         var_SetBool( THEPL, "repeat", false );
1149     else if( var_GetBool( THEPL, "loop" ) )
1150     {
1151         var_SetBool( THEPL, "loop", false );
1152         var_SetBool( THEPL, "repeat", true );
1153     }
1154     else
1155         var_SetBool( THEPL, "loop", true );
1156 }
1157
1158 void MainInputManager::activatePlayQuit( bool b_exit )
1159 {
1160     var_SetBool( THEPL, "play-and-exit", b_exit );
1161 }
1162
1163 bool MainInputManager::getPlayExitState()
1164 {
1165     return var_GetBool( THEPL, "play-and-exit" );
1166 }
1167
1168 /****************************
1169  * Static callbacks for MIM *
1170  ****************************/
1171 static int PLItemChanged( vlc_object_t *p_this, const char *psz_var,
1172                         vlc_value_t oldval, vlc_value_t, void *param )
1173 {
1174     VLC_UNUSED( p_this ); VLC_UNUSED( psz_var ); VLC_UNUSED( oldval );
1175
1176     MainInputManager *mim = (MainInputManager*)param;
1177
1178     IMEvent *event = new IMEvent( ItemChanged_Type );
1179     QApplication::postEvent( mim, event );
1180     return VLC_SUCCESS;
1181 }
1182
1183 static int LeafToParent( vlc_object_t *p_this, const char *psz_var,
1184                         vlc_value_t oldval, vlc_value_t newval, void *param )
1185 {
1186     VLC_UNUSED( p_this ); VLC_UNUSED( psz_var ); VLC_UNUSED( oldval );
1187     MainInputManager *mim = (MainInputManager*)param;
1188
1189     PLEvent *event = new PLEvent( LeafToParent_Type, newval.i_int );
1190
1191     QApplication::postEvent( mim, event );
1192     return VLC_SUCCESS;
1193 }
1194
1195 static int VolumeChanged( vlc_object_t *p_this, const char *psz_var,
1196                         vlc_value_t oldval, vlc_value_t newval, void *param )
1197 {
1198     VLC_UNUSED( p_this ); VLC_UNUSED( psz_var ); VLC_UNUSED( oldval ); VLC_UNUSED( newval );
1199
1200     MainInputManager *mim = (MainInputManager*)param;
1201
1202     IMEvent *event = new IMEvent( VolumeChanged_Type );
1203     QApplication::postEvent( mim, event );
1204     return VLC_SUCCESS;
1205 }
1206
1207 static int SoundMuteChanged( vlc_object_t *p_this, const char *psz_var,
1208                         vlc_value_t oldval, vlc_value_t newval, void *param )
1209 {
1210     VLC_UNUSED( p_this ); VLC_UNUSED( psz_var ); VLC_UNUSED( oldval ); VLC_UNUSED( newval );
1211
1212     MainInputManager *mim = (MainInputManager*)param;
1213
1214     IMEvent *event = new IMEvent( SoundMuteChanged_Type );
1215     QApplication::postEvent( mim, event );
1216     return VLC_SUCCESS;
1217 }
1218
1219 static int PLItemAppended
1220 ( vlc_object_t * obj, const char *var, vlc_value_t old, vlc_value_t cur, void *data )
1221 {
1222     VLC_UNUSED( obj ); VLC_UNUSED( var ); VLC_UNUSED( old );
1223
1224     MainInputManager *mim = static_cast<MainInputManager*>(data);
1225     playlist_add_t *p_add = static_cast<playlist_add_t*>( cur.p_address );
1226
1227     PLEvent *event = new PLEvent( PLItemAppended_Type, p_add->i_item, p_add->i_node  );
1228     QApplication::postEvent( mim, event );
1229     return VLC_SUCCESS;
1230 }
1231 static int PLItemRemoved
1232 ( vlc_object_t * obj, const char *var, vlc_value_t old, vlc_value_t cur, void *data )
1233 {
1234     VLC_UNUSED( obj ); VLC_UNUSED( var ); VLC_UNUSED( old );
1235
1236     MainInputManager *mim = static_cast<MainInputManager*>(data);
1237
1238     PLEvent *event = new PLEvent( PLItemRemoved_Type, cur.i_int, 0  );
1239     QApplication::postEvent( mim, event );
1240     return VLC_SUCCESS;
1241 }
1242
1243 static int RandomChanged
1244 ( vlc_object_t * obj, const char *var, vlc_value_t old, vlc_value_t cur, void *data )
1245 {
1246     VLC_UNUSED( obj ); VLC_UNUSED( var ); VLC_UNUSED( old ); VLC_UNUSED( cur );
1247
1248     MainInputManager *mim = static_cast<MainInputManager*>(data);
1249
1250     IMEvent *event = new IMEvent( RandomChanged_Type );
1251     QApplication::postEvent( mim, event );
1252     return VLC_SUCCESS;
1253 }
1254
1255 /* Probably could be merged with next callback */
1256 static int LoopChanged
1257 ( vlc_object_t * obj, const char *var, vlc_value_t old, vlc_value_t cur, void *data )
1258 {
1259     VLC_UNUSED( obj ); VLC_UNUSED( var ); VLC_UNUSED( old ); VLC_UNUSED( cur );
1260
1261     MainInputManager *mim = static_cast<MainInputManager*>(data);
1262
1263     IMEvent *event = new IMEvent( LoopChanged_Type );
1264     QApplication::postEvent( mim, event );
1265     return VLC_SUCCESS;
1266 }
1267
1268 static int RepeatChanged
1269 ( vlc_object_t * obj, const char *var, vlc_value_t old, vlc_value_t cur, void *data )
1270 {
1271     VLC_UNUSED( obj ); VLC_UNUSED( var ); VLC_UNUSED( old ); VLC_UNUSED( cur );
1272
1273     MainInputManager *mim = static_cast<MainInputManager*>(data);
1274
1275     IMEvent *event = new IMEvent( RepeatChanged_Type );
1276     QApplication::postEvent( mim, event );
1277     return VLC_SUCCESS;
1278 }