]> git.sesse.net Git - vlc/blob - modules/gui/qt4/input_manager.cpp
Qt: react to caching Event from input to display Buffering.
[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 #ifdef HAVE_CONFIG_H
27 # include "config.h"
28 #endif
29
30 #include "input_manager.hpp"
31
32 #include <QApplication>
33
34 static int ItemChanged( vlc_object_t *, const char *,
35                         vlc_value_t, vlc_value_t, void * );
36 static int PLItemChanged( vlc_object_t *, const char *,
37                         vlc_value_t, vlc_value_t, void * );
38 static int VolumeChanged( vlc_object_t *, const char *,
39                         vlc_value_t, vlc_value_t, void * );
40
41 static int InputEvent( vlc_object_t *, const char *,
42                        vlc_value_t, vlc_value_t, void * );
43
44
45 /**********************************************************************
46  * InputManager implementation
47  **********************************************************************
48  * The Input Manager can be the main one around the playlist
49  * But can also be used for VLM dialog or similar
50  **********************************************************************/
51
52 InputManager::InputManager( QObject *parent, intf_thread_t *_p_intf) :
53                            QObject( parent ), p_intf( _p_intf )
54 {
55     i_old_playing_status = END_S;
56     oldName      = "";
57     artUrl       = "";
58     p_input      = NULL;
59     i_rate       = 0;
60     i_input_id   = 0;
61     b_video      = false;
62     timeA        = 0;
63     timeB        = 0;
64
65 }
66
67 InputManager::~InputManager()
68 {
69     delInput();
70 }
71
72 /* Define the Input used.
73    Add the callbacks on input
74    p_input is held once here */
75 void InputManager::setInput( input_thread_t *_p_input )
76 {
77     delInput();
78     p_input = _p_input;
79     if( p_input && !( p_input->b_dead || !vlc_object_alive (p_input) ) )
80     {
81         msg_Dbg( p_intf, "IM: Setting an input" );
82         vlc_object_hold( p_input );
83         emit statusChanged( PLAYING_S );
84         UpdateName();
85         UpdateArt();
86         UpdateTeletext();
87         UpdateNavigation();
88         UpdateVout();
89         addCallbacks();
90         i_input_id = input_GetItem( p_input )->i_id;
91     }
92     else
93     {
94         p_input = NULL;
95         i_input_id = 0;
96         emit rateChanged( INPUT_RATE_DEFAULT );
97     }
98 }
99
100 /* delete Input if it ever existed.
101    Delete the callbacls on input
102    p_input is released once here */
103 void InputManager::delInput()
104 {
105     if( !p_input ) return;
106     msg_Dbg( p_intf, "IM: Deleting the input" );
107
108     delCallbacks();
109     i_old_playing_status = END_S;
110     i_input_id           = 0;
111     oldName              = "";
112     artUrl               = "";
113     b_video              = false;
114     timeA                = 0;
115     timeB                = 0;
116
117     vlc_object_release( p_input );
118     p_input = NULL;
119
120     emit positionUpdated( -1.0, 0 ,0 );
121     emit rateChanged( INPUT_RATE_DEFAULT ); /* TODO: Do we want this ? */
122     emit nameChanged( "" );
123     emit chapterChanged( 0 );
124     emit titleChanged( 0 );
125     emit statusChanged( END_S );
126
127     emit teletextPossible( false );
128     emit AtoBchanged( false, false );
129     emit voutChanged( false );
130
131     /* Reset all InfoPanels but stats */
132     emit artChanged( NULL );
133     emit infoChanged( NULL );
134     emit metaChanged( NULL );
135 }
136
137 /* Add the callbacks on Input. Self explanatory */
138 inline void InputManager::addCallbacks()
139 {
140     var_AddCallback( p_input, "intf-event", InputEvent, this );
141 }
142
143 /* Delete the callbacks on Input. Self explanatory */
144 inline void InputManager::delCallbacks()
145 {
146     var_DelCallback( p_input, "intf-event", InputEvent, this );
147 }
148
149 /* Convert the event from the callbacks in actions */
150 void InputManager::customEvent( QEvent *event )
151 {
152     int i_type = event->type();
153     IMEvent *ple = static_cast<IMEvent *>(event);
154
155     if ( i_type != PositionUpdate_Type &&
156          i_type != ItemChanged_Type &&
157          i_type != ItemRateChanged_Type &&
158          i_type != ItemTitleChanged_Type &&
159          i_type != ItemEsChanged_Type &&
160          i_type != ItemTeletextChanged_Type &&
161          i_type != ItemStateChanged_Type &&
162          i_type != StatisticsUpdate_Type &&
163          i_type != InterfaceVoutUpdate_Type &&
164          i_type != MetaChanged_Type &&
165          i_type != NameChanged_Type &&
166          i_type != InfoChanged_Type &&
167          i_type != SynchroChanged_Type &&
168          i_type != CachingEvent_Type )
169         return;
170
171     if( i_type == CachingEvent_Type )
172         UpdateCaching();
173
174     if( !hasInput() ) return;
175
176     if( ( i_type != PositionUpdate_Type  &&
177           i_type != ItemRateChanged_Type &&
178           i_type != ItemEsChanged_Type &&
179           i_type != ItemTeletextChanged_Type &&
180           i_type != ItemStateChanged_Type &&
181           i_type != StatisticsUpdate_Type &&
182           i_type != InterfaceVoutUpdate_Type &&
183           i_type != MetaChanged_Type &&
184           i_type != NameChanged_Type &&
185           i_type != InfoChanged_Type &&
186           i_type != SynchroChanged_Type
187         )
188         && ( i_input_id != ple->i_id ) )
189         return;
190
191 #ifndef NDEBUG
192     if( i_type != PositionUpdate_Type &&
193         i_type != StatisticsUpdate_Type )
194         msg_Dbg( p_intf, "New Event: type %i", i_type );
195 #endif
196
197     /* Actions */
198     switch( i_type )
199     {
200     case PositionUpdate_Type:
201         UpdatePosition();
202         break;
203     case StatisticsUpdate_Type:
204         UpdateStats();
205         break;
206     case ItemChanged_Type:
207         UpdateStatus();
208         // UpdateName();
209         // UpdateArt();
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         // We don't do anything. Why ?
238         break;
239     case ItemTeletextChanged_Type:
240         UpdateTeletext();
241         break;
242     case InterfaceVoutUpdate_Type:
243         UpdateVout();
244         break;
245     case SynchroChanged_Type:
246         emit synchroChanged();
247         break;
248     case CachingEvent_Type:
249         UpdateCaching();
250         break;
251     default:
252         msg_Warn( p_intf, "This shouldn't happen: %i", i_type );
253     }
254 }
255
256 void InputManager::UpdatePosition()
257 {
258     /* Update position */
259     int i_length, i_time; /* Int is enough, since we store seconds */
260     float f_pos;
261     i_length = var_GetTime(  p_input , "length" ) / 1000000;
262     i_time = var_GetTime(  p_input , "time") / 1000000;
263     f_pos = var_GetFloat(  p_input , "position" );
264     emit positionUpdated( f_pos, i_time, i_length );
265 }
266
267 void InputManager::UpdateNavigation()
268 {
269     /* Update navigation status */
270     vlc_value_t val; val.i_int = 0;
271
272     if( hasInput() )
273         var_Change( p_input, "title", VLC_VAR_CHOICESCOUNT, &val, NULL );
274
275     if( val.i_int > 0 )
276     {
277         emit titleChanged( true );
278         /* p_input != NULL since val.i_int != 0 */
279         val.i_int = 0;
280         var_Change( p_input, "chapter", VLC_VAR_CHOICESCOUNT, &val, NULL );
281         emit chapterChanged( (val.i_int > 0) );
282     }
283     else
284         emit titleChanged( false );
285 }
286
287 void InputManager::UpdateStatus()
288 {
289     /* Update playing status */
290     vlc_value_t val; val.i_int = 0;
291     var_Get( p_input, "state", &val );
292     if( i_old_playing_status != val.i_int )
293     {
294         i_old_playing_status = val.i_int;
295         emit statusChanged( val.i_int );
296     }
297 }
298
299 void InputManager::UpdateRate()
300 {
301     /* Update Rate */
302     int i_new_rate = var_GetInteger( p_input, "rate");
303     if( i_new_rate != i_rate )
304     {
305         i_rate = i_new_rate;
306         /* Update rate */
307         emit rateChanged( i_rate );
308     }
309 }
310
311 void InputManager::UpdateName()
312 {
313     /* Update text, name and nowplaying */
314     QString text;
315
316     /* Try to get the Title, then the Name */
317     char *psz_name = input_item_GetTitle( input_GetItem( p_input ) );
318     if( EMPTY_STR( psz_name ) )
319     {
320         free( psz_name );
321         psz_name = input_item_GetName( input_GetItem( p_input ) );
322     }
323
324     /* Try to get the nowplaying */
325     char *psz_nowplaying =
326         input_item_GetNowPlaying( input_GetItem( p_input ) );
327     if( !EMPTY_STR( psz_nowplaying ) )
328     {
329         text.sprintf( "%s - %s", psz_nowplaying, psz_name );
330     }
331     else  /* Do it ourself */
332     {
333         char *psz_artist = input_item_GetArtist( input_GetItem( p_input ) );
334
335         if( !EMPTY_STR( psz_artist ) )
336             text.sprintf( "%s - %s", psz_artist, psz_name );
337         else
338             text.sprintf( "%s", psz_name );
339
340         free( psz_artist );
341     }
342     /* Free everything */
343     free( psz_name );
344     free( psz_nowplaying );
345
346     /* If we have Nothing */
347     if( text.isEmpty() )
348     {
349         psz_name = input_item_GetURI( input_GetItem( p_input ) );
350         text.sprintf( "%s", psz_name );
351         text = text.remove( 0, text.lastIndexOf( DIR_SEP ) + 1 );
352         free( psz_name );
353     }
354
355     if( oldName != text )
356     {
357         emit nameChanged( text );
358         oldName = text;
359     }
360 }
361
362 bool InputManager::hasAudio()
363 {
364     if( hasInput() )
365     {
366         vlc_value_t val;
367         var_Change( p_input, "audio-es", VLC_VAR_CHOICESCOUNT, &val, NULL );
368         return val.i_int > 0;
369     }
370     return false;
371 }
372
373 void InputManager::UpdateTeletext()
374 {
375     if( hasInput() )
376         telexActivation( var_GetInteger( p_input, "teletext-es" ) >= 0 );
377     else
378         telexActivation( false );
379 }
380
381 void InputManager::UpdateVout()
382 {
383     if( hasInput() )
384     {
385         bool b_old_video = b_video;
386
387         vlc_object_t *p_vout = (vlc_object_t*)vlc_object_find( p_input,
388                                          VLC_OBJECT_VOUT, FIND_CHILD );
389         b_video = p_vout != NULL;
390         if( p_vout )
391             vlc_object_release( p_vout );
392         if( !!b_old_video != !!b_video )
393             emit voutChanged( b_video );
394     }
395 }
396
397 void InputManager::UpdateCaching()
398 {
399     float f_newCache = var_GetFloat( p_input, "cache" );
400     if( f_newCache != f_cache )
401     {
402         f_newCache = f_cache;
403         /* Update rate */
404         emit cachingChanged( f_cache );
405     }
406 }
407
408 inline void InputManager::UpdateArt()
409 {
410     /* Update Art meta */
411     emit artChanged( input_GetItem( p_input ) );
412 }
413
414 inline void InputManager::UpdateStats()
415 {
416     emit statisticsUpdated( input_GetItem( p_input ) );
417 }
418
419 inline void InputManager::UpdateMeta()
420 {
421     emit metaChanged( input_GetItem( p_input ) );
422 }
423
424 inline void InputManager::UpdateInfo()
425 {
426     emit infoChanged( input_GetItem( p_input ) );
427 }
428
429 /* User update of the slider */
430 void InputManager::sliderUpdate( float new_pos )
431 {
432     if( hasInput() )
433         var_SetFloat( p_input, "position", new_pos );
434 }
435
436 /* User togglePlayPause */
437 void InputManager::togglePlayPause()
438 {
439     vlc_value_t state;
440     if( hasInput() )
441     {
442         var_Get( p_input, "state", &state );
443         state.i_int = ( state.i_int != PLAYING_S ) ? PLAYING_S : PAUSE_S;
444         var_Set( p_input, "state", state );
445         emit statusChanged( state.i_int );
446     }
447 }
448
449 void InputManager::sectionPrev()
450 {
451     if( hasInput() )
452     {
453         int i_type = var_Type( p_input, "next-chapter" );
454         vlc_value_t val; val.b_bool = true;
455         var_Set( p_input, (i_type & VLC_VAR_TYPE) != 0 ?
456                             "prev-chapter":"prev-title", val );
457     }
458 }
459
460 void InputManager::sectionNext()
461 {
462     if( hasInput() )
463     {
464         int i_type = var_Type( p_input, "next-chapter" );
465         vlc_value_t val; val.b_bool = true;
466         var_Set( p_input, (i_type & VLC_VAR_TYPE) != 0 ?
467                             "next-chapter":"next-title", val );
468     }
469 }
470
471 void InputManager::sectionMenu()
472 {
473     if( hasInput() )
474     {
475         vlc_value_t val, text;
476         vlc_value_t root;
477
478         if( var_Change( p_input, "title  0", VLC_VAR_GETLIST, &val, &text ) < 0 )
479             return;
480
481         /* XXX is it "Root" or "Title" we want here ?" (set 0 by default) */
482         root.i_int = 0;
483         for( int i = 0; i < val.p_list->i_count; i++ )
484         {
485             if( !strcmp( text.p_list->p_values[i].psz_string, "Title" ) )
486                 root.i_int = i;
487         }
488         var_Change( p_input, "title  0", VLC_VAR_FREELIST, &val, &text );
489
490         var_Set( p_input, "title  0", root );
491     }
492 }
493
494 /*
495  *  Teletext Functions
496  */
497
498 /* Set a new Teletext Page */
499 void InputManager::telexSetPage( int page )
500 {
501     if( hasInput() )
502     {
503         const int i_teletext_es = var_GetInteger( p_input, "teletext-es" );
504         const int i_spu_es = var_GetInteger( p_input, "spu-es" );
505
506         if( i_teletext_es >= 0 && i_teletext_es == i_spu_es )
507         {
508             vlc_object_t *p_vbi = (vlc_object_t *) vlc_object_find_name( p_input,
509                         "zvbi", FIND_ANYWHERE );
510             if( p_vbi )
511             {
512                 var_SetInteger( p_vbi, "vbi-page", page );
513                 vlc_object_release( p_vbi );
514                 emit newTelexPageSet( page );
515             }
516         }
517     }
518 }
519
520 /* Set the transparency on teletext */
521 void InputManager::telexSetTransparency( bool b_transparentTelextext )
522 {
523     if( hasInput() )
524     {
525         vlc_object_t *p_vbi = (vlc_object_t *) vlc_object_find_name( p_input,
526                     "zvbi", FIND_ANYWHERE );
527         if( p_vbi )
528         {
529             var_SetBool( p_vbi, "vbi-opaque", b_transparentTelextext );
530             vlc_object_release( p_vbi );
531             emit teletextTransparencyActivated( b_transparentTelextext );
532         }
533     }
534 }
535
536 void InputManager::telexActivation( bool b_enabled )
537 {
538     if( hasInput() )
539     {
540         const int i_teletext_es = var_GetInteger( p_input, "teletext-es" );
541         const int i_spu_es = var_GetInteger( p_input, "spu-es" );
542
543         /* Teletext is possible. Show the buttons */
544         b_enabled = (i_teletext_es >= 0);
545         emit teletextPossible( b_enabled );
546         if( !b_enabled ) return;
547
548         /* If Teletext is selected */
549         if( i_teletext_es == i_spu_es )
550         {
551             /* Activate the buttons */
552             teletextActivated( true );
553
554             /* Then, find the current page */
555             int i_page = 100;
556             vlc_object_t *p_vbi = (vlc_object_t *)
557                 vlc_object_find_name( p_input, "zvbi", FIND_ANYWHERE );
558             if( p_vbi )
559             {
560                 i_page = var_GetInteger( p_vbi, "vbi-page" );
561                 vlc_object_release( p_vbi );
562                 emit newTelexPageSet( i_page );
563             }
564         }
565     }
566     else
567         emit teletextPossible( b_enabled );
568 }
569
570 void InputManager::activateTeletext( bool b_enable )
571 {
572     if( hasInput() )
573     {
574         const int i_teletext_es = var_GetInteger( p_input, "teletext-es" );
575         if( i_teletext_es >= 0 )
576         {
577             var_SetInteger( p_input, "spu-es", b_enable ? i_teletext_es : -1 );
578         }
579     }
580 }
581
582 void InputManager::reverse()
583 {
584     if( hasInput() )
585     {
586         int i_rate = var_GetInteger( p_input, "rate" );
587         var_SetInteger( p_input, "rate", -i_rate );
588     }
589 }
590
591 void InputManager::slower()
592 {
593     if( hasInput() )
594         var_SetVoid( p_input, "rate-slower" );
595 }
596
597 void InputManager::faster()
598 {
599     if( hasInput() )
600         var_SetVoid( p_input, "rate-faster" );
601 }
602
603 void InputManager::normalRate()
604 {
605     if( hasInput() )
606         var_SetInteger( p_input, "rate", INPUT_RATE_DEFAULT );
607 }
608
609 void InputManager::setRate( int new_rate )
610 {
611     if( hasInput() )
612         var_SetInteger( p_input, "rate", new_rate );
613 }
614
615 void InputManager::setAtoB()
616 {
617     if( !timeA )
618     {
619         timeA = var_GetTime( THEMIM->getInput(), "time"  );
620     }
621     else if( !timeB )
622     {
623         timeB = var_GetTime( THEMIM->getInput(), "time"  );
624         var_SetTime( THEMIM->getInput(), "time" , timeA );
625     }
626     else
627     {
628         timeA = 0;
629         timeB = 0;
630     }
631     emit AtoBchanged( (timeA != 0 ), (timeB != 0 ) );
632 }
633
634 /* Function called regularly when in an AtoB loop */
635 void InputManager::AtoBLoop( int i_time )
636 {
637     if( timeB )
638     {
639         if( ( i_time >= (int)( timeB/1000000 ) )
640             || ( i_time < (int)( timeA/1000000 ) ) )
641             var_SetTime( THEMIM->getInput(), "time" , timeA );
642     }
643 }
644
645 /**********************************************************************
646  * MainInputManager implementation. Wrap an input manager and
647  * take care of updating the main playlist input.
648  * Used in the main playlist Dialog
649  **********************************************************************/
650 MainInputManager * MainInputManager::instance = NULL;
651
652 MainInputManager::MainInputManager( intf_thread_t *_p_intf )
653                  : QObject(NULL), p_intf( _p_intf )
654 {
655     p_input = NULL;
656     im = new InputManager( this, p_intf );
657
658     var_AddCallback( THEPL, "item-change", ItemChanged, im );
659     var_AddCallback( THEPL, "playlist-current", PLItemChanged, this );
660     var_AddCallback( THEPL, "activity", PLItemChanged, this );
661
662     var_AddCallback( p_intf->p_libvlc, "volume-change", VolumeChanged, this );
663
664     /* Warn our embedded IM about input changes */
665     CONNECT( this, inputChanged( input_thread_t * ),
666              im, setInput( input_thread_t * ) );
667
668     /* emit check if playlist has allready started playing */
669     vlc_value_t val;
670     var_Change( THEPL, "playlist-current", VLC_VAR_CHOICESCOUNT, &val, NULL );
671     IMEvent *event = new IMEvent( ItemChanged_Type, val.i_int);
672     QApplication::postEvent( this, static_cast<QEvent*>(event) );
673 }
674
675 MainInputManager::~MainInputManager()
676 {
677     if( p_input )
678     {
679        var_DelCallback( p_input, "state", PLItemChanged, this );
680        vlc_object_release( p_input );
681        emit inputChanged( NULL );
682     }
683
684     var_DelCallback( p_intf->p_libvlc, "volume-change", VolumeChanged, this );
685
686     var_DelCallback( THEPL, "activity", PLItemChanged, this );
687     var_DelCallback( THEPL, "item-change", ItemChanged, im );
688
689     var_DelCallback( THEPL, "playlist-current", PLItemChanged, this );
690 }
691
692 void MainInputManager::customEvent( QEvent *event )
693 {
694     int type = event->type();
695     if ( type != ItemChanged_Type && type != VolumeChanged_Type )
696         return;
697
698     // msg_Dbg( p_intf, "New MainIM Event of type: %i", type );
699     if( type == VolumeChanged_Type )
700     {
701         emit volumeChanged();
702         return;
703     }
704
705     /* Should be PLItemChanged Event */
706     if( !p_intf->p_sys->b_isDialogProvider )
707     {
708         vlc_mutex_lock( &p_intf->change_lock );
709         if( p_input && ( p_input->b_dead || !vlc_object_alive (p_input) ) )
710         {
711             var_DelCallback( p_input, "state", PLItemChanged, this );
712             vlc_object_release( p_input );
713             emit inputChanged( NULL );
714             p_input = NULL;
715             vlc_mutex_unlock( &p_intf->change_lock );
716             return;
717         }
718
719         if( !p_input )
720         {
721             p_input = playlist_CurrentInput(THEPL);
722             if( p_input )
723             {
724                 var_AddCallback( p_input, "state", PLItemChanged, this );
725                 emit inputChanged( p_input );
726             }
727         }
728         vlc_mutex_unlock( &p_intf->change_lock );
729     }
730     else
731     {
732         /* we are working as a dialogs provider */
733         playlist_t *p_playlist = pl_Hold( p_intf );
734         p_input = playlist_CurrentInput( p_playlist );
735         if( p_input )
736         {
737             emit inputChanged( p_input );
738             vlc_object_release( p_input );
739         }
740         pl_Release( p_intf );
741     }
742 }
743
744 /* Playlist Control functions */
745 void MainInputManager::stop()
746 {
747    playlist_Stop( THEPL );
748 }
749
750 void MainInputManager::next()
751 {
752    playlist_Next( THEPL );
753 }
754
755 void MainInputManager::prev()
756 {
757    playlist_Prev( THEPL );
758 }
759
760 void MainInputManager::togglePlayPause()
761 {
762     /* No input, play */
763     if( !p_input )
764         playlist_Play( THEPL );
765     else
766         getIM()->togglePlayPause();
767 }
768
769 /* Static callbacks */
770
771 /* IM */
772 static int ItemChanged( vlc_object_t *p_this, const char *psz_var,
773                         vlc_value_t oldval, vlc_value_t newval, void *param )
774 {
775     InputManager *im = (InputManager*)param;
776
777     IMEvent *event = new IMEvent( ItemChanged_Type, newval.i_int );
778     QApplication::postEvent( im, static_cast<QEvent*>(event) );
779     return VLC_SUCCESS;
780 }
781
782 static int InputEvent( vlc_object_t *p_this, const char *,
783                        vlc_value_t, vlc_value_t newval, void *param )
784 {
785     InputManager *im = (InputManager*)param;
786     IMEvent *event;
787
788     switch( newval.i_int )
789     {
790     case INPUT_EVENT_STATE:
791         event = new IMEvent( ItemStateChanged_Type, 0 );
792         break;
793     case INPUT_EVENT_RATE:
794         event = new IMEvent( ItemRateChanged_Type, 0 );
795         break;
796     case INPUT_EVENT_TIMES:
797         event = new IMEvent( PositionUpdate_Type, 0 );
798         break;
799
800     case INPUT_EVENT_TITLE:
801     case INPUT_EVENT_CHAPTER:
802         event = new IMEvent( ItemTitleChanged_Type, 0 );
803         break;
804
805     case INPUT_EVENT_ES:
806         event = new IMEvent( ItemEsChanged_Type, 0 );
807         break;
808     case INPUT_EVENT_TELETEXT:
809         event = new IMEvent( ItemTeletextChanged_Type, 0 );
810         break;
811
812     case INPUT_EVENT_VOUT:
813         event = new IMEvent( InterfaceVoutUpdate_Type, 0 );
814         break;
815
816     case INPUT_EVENT_STATISTICS:
817         event = new IMEvent( StatisticsUpdate_Type, 0 );
818         break;
819
820     case INPUT_EVENT_ITEM_META: /* Codec MetaData + Art */
821         event = new IMEvent( MetaChanged_Type, 0 );
822         break;
823     case INPUT_EVENT_ITEM_INFO: /* Codec Info */
824         event = new IMEvent( InfoChanged_Type, 0 );
825         break;
826     case INPUT_EVENT_ITEM_NAME:
827         event = new IMEvent( NameChanged_Type, 0 );
828         break;
829
830     case INPUT_EVENT_AUDIO_DELAY:
831     case INPUT_EVENT_SUBTITLE_DELAY:
832         event = new IMEvent( SynchroChanged_Type, 0 );
833         break;
834
835     case INPUT_EVENT_CACHE:
836         event = new IMEvent( CachingEvent_Type, 0 );
837         break;
838
839     case INPUT_EVENT_PROGRAM:
840     case INPUT_EVENT_RECORD:
841     case INPUT_EVENT_SIGNAL:
842     case INPUT_EVENT_BOOKMARK:
843     default:
844         event = NULL;
845         break;
846     }
847
848     if( event )
849         QApplication::postEvent( im, static_cast<QEvent*>(event) );
850     return VLC_SUCCESS;
851 }
852
853 /* MIM */
854 static int PLItemChanged( vlc_object_t *p_this, const char *psz_var,
855                         vlc_value_t oldval, vlc_value_t newval, void *param )
856 {
857     MainInputManager *mim = (MainInputManager*)param;
858
859     IMEvent *event = new IMEvent( ItemChanged_Type, newval.i_int );
860     QApplication::postEvent( mim, static_cast<QEvent*>(event) );
861     return VLC_SUCCESS;
862 }
863
864 static int VolumeChanged( vlc_object_t *p_this, const char *psz_var,
865                         vlc_value_t oldval, vlc_value_t newval, void *param )
866 {
867     MainInputManager *mim = (MainInputManager*)param;
868
869     IMEvent *event = new IMEvent( VolumeChanged_Type, newval.i_int );
870     QApplication::postEvent( mim, static_cast<QEvent*>(event) );
871     return VLC_SUCCESS;
872 }
873
874