1 /*****************************************************************************
2 * input_manager.cpp : Manage an input and interact with its GUI elements
3 ****************************************************************************
4 * Copyright (C) 2006-2008 the VideoLAN team
7 * Authors: Clément Stenac <zorglub@videolan.org>
8 * Ilkka Ollakka <ileoo@videolan.org>
9 * Jean-Baptiste <jb@videolan.org>
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.
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.
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 *****************************************************************************/
30 #include "input_manager.hpp"
34 #include <QApplication>
38 static int ItemChanged( vlc_object_t *, const char *,
39 vlc_value_t, vlc_value_t, void * );
40 static int PLItemChanged( vlc_object_t *, const char *,
41 vlc_value_t, vlc_value_t, void * );
42 static int PLItemAppended( vlc_object_t *, const char *,
43 vlc_value_t, vlc_value_t, void * );
44 static int PLItemRemoved( vlc_object_t *, const char *,
45 vlc_value_t, vlc_value_t, void * );
46 static int VolumeChanged( vlc_object_t *, const char *,
47 vlc_value_t, vlc_value_t, void * );
49 static int RandomChanged( vlc_object_t *, const char *,
50 vlc_value_t, vlc_value_t, void * );
51 static int LoopChanged( vlc_object_t *, const char *,
52 vlc_value_t, vlc_value_t, void * );
53 static int RepeatChanged( vlc_object_t *, const char *,
54 vlc_value_t, vlc_value_t, void * );
57 static int InputEvent( vlc_object_t *, const char *,
58 vlc_value_t, vlc_value_t, void * );
59 static int VbiEvent( vlc_object_t *, const char *,
60 vlc_value_t, vlc_value_t, void * );
63 /**********************************************************************
64 * InputManager implementation
65 **********************************************************************
66 * The Input Manager can be the main one around the playlist
67 * But can also be used for VLM dialog or similar
68 **********************************************************************/
70 InputManager::InputManager( QObject *parent, intf_thread_t *_p_intf) :
71 QObject( parent ), p_intf( _p_intf )
73 i_old_playing_status = END_S;
82 f_cache = -1.; /* impossible initial value, different from all */
85 InputManager::~InputManager()
90 /* Define the Input used.
91 Add the callbacks on input
92 p_input is held once here */
93 void InputManager::setInput( input_thread_t *_p_input )
97 if( p_input && !( p_input->b_dead || !vlc_object_alive (p_input) ) )
99 msg_Dbg( p_intf, "IM: Setting an input" );
100 vlc_object_hold( p_input );
101 emit statusChanged( PLAYING_S );
108 p_item = input_GetItem( p_input );
114 emit rateChanged( INPUT_RATE_DEFAULT );
118 /* delete Input if it ever existed.
119 Delete the callbacls on input
120 p_input is released once here */
121 void InputManager::delInput()
123 if( !p_input ) return;
124 msg_Dbg( p_intf, "IM: Deleting the input" );
127 i_old_playing_status = END_S;
135 vlc_object_release( p_input );
138 emit positionUpdated( -1.0, 0 ,0 );
139 emit rateChanged( INPUT_RATE_DEFAULT ); /* TODO: Do we want this ? */
140 emit nameChanged( "" );
141 emit chapterChanged( 0 );
142 emit titleChanged( 0 );
143 emit statusChanged( END_S );
145 emit teletextPossible( false );
146 emit AtoBchanged( false, false );
147 emit voutChanged( false );
148 emit voutListChanged( NULL, 0 );
150 /* Reset all InfoPanels but stats */
151 emit artChanged( NULL );
152 emit infoChanged( NULL );
153 emit currentMetaChanged( (input_item_t *)NULL );
155 emit encryptionChanged( false );
156 emit recordingStateChanged( false );
159 /* Convert the event from the callbacks in actions */
160 void InputManager::customEvent( QEvent *event )
162 int i_type = event->type();
163 IMEvent *ple = static_cast<IMEvent *>(event);
165 if( i_type == ItemChanged_Type )
166 UpdateMeta( ple->p_item );
174 case PositionUpdate_Type:
177 case StatisticsUpdate_Type:
180 case ItemChanged_Type:
181 /* Ignore ItemChanged_Type event that does not apply to our input */
182 if( p_item == ple->p_item )
187 /* Update duration of file */
190 case ItemStateChanged_Type:
191 // TODO: Fusion with above state
194 // UpdateNavigation(); This shouldn't be useful now
195 // UpdateTeletext(); Same
197 case NameChanged_Type:
200 case MetaChanged_Type:
202 UpdateName(); /* Needed for NowPlaying */
203 UpdateArt(); /* Art is part of meta in the core */
205 case InfoChanged_Type:
208 case ItemTitleChanged_Type:
210 UpdateName(); /* Display the name of the Chapter, if exists */
212 case ItemRateChanged_Type:
215 case ItemEsChanged_Type:
217 // We don't do anything ES related. Why ?
219 case ItemTeletextChanged_Type:
222 case InterfaceVoutUpdate_Type:
225 case SynchroChanged_Type:
226 emit synchroChanged();
228 case CachingEvent_Type:
231 case BookmarksChanged_Type:
232 emit bookmarksChanged();
234 case InterfaceAoutUpdate_Type:
237 case RecordingEvent_Type:
240 case ProgramChanged_Type:
241 UpdateProgramEvent();
244 msg_Warn( p_intf, "This shouldn't happen: %i", i_type );
249 /* Add the callbacks on Input. Self explanatory */
250 inline void InputManager::addCallbacks()
252 var_AddCallback( p_input, "intf-event", InputEvent, this );
255 /* Delete the callbacks on Input. Self explanatory */
256 inline void InputManager::delCallbacks()
258 var_DelCallback( p_input, "intf-event", InputEvent, this );
261 /* Static callbacks for IM */
262 static int ItemChanged( vlc_object_t *p_this, const char *psz_var,
263 vlc_value_t oldval, vlc_value_t newval, void *param )
265 InputManager *im = (InputManager*)param;
266 input_item_t *p_item = static_cast<input_item_t *>(newval.p_address);
268 IMEvent *event = new IMEvent( ItemChanged_Type, p_item );
269 QApplication::postEvent( im, event );
273 static int InputEvent( vlc_object_t *p_this, const char *,
274 vlc_value_t, vlc_value_t newval, void *param )
276 InputManager *im = (InputManager*)param;
279 switch( newval.i_int )
281 case INPUT_EVENT_STATE:
282 event = new IMEvent( ItemStateChanged_Type );
284 case INPUT_EVENT_RATE:
285 event = new IMEvent( ItemRateChanged_Type );
287 case INPUT_EVENT_POSITION:
288 //case INPUT_EVENT_LENGTH:
289 event = new IMEvent( PositionUpdate_Type );
292 case INPUT_EVENT_TITLE:
293 case INPUT_EVENT_CHAPTER:
294 event = new IMEvent( ItemTitleChanged_Type );
298 event = new IMEvent( ItemEsChanged_Type );
300 case INPUT_EVENT_TELETEXT:
301 event = new IMEvent( ItemTeletextChanged_Type );
304 case INPUT_EVENT_STATISTICS:
305 event = new IMEvent( StatisticsUpdate_Type );
308 case INPUT_EVENT_VOUT:
309 event = new IMEvent( InterfaceVoutUpdate_Type );
311 case INPUT_EVENT_AOUT:
312 event = new IMEvent( InterfaceAoutUpdate_Type );
315 case INPUT_EVENT_ITEM_META: /* Codec MetaData + Art */
316 event = new IMEvent( MetaChanged_Type );
318 case INPUT_EVENT_ITEM_INFO: /* Codec Info */
319 event = new IMEvent( InfoChanged_Type );
321 case INPUT_EVENT_ITEM_NAME:
322 event = new IMEvent( NameChanged_Type );
325 case INPUT_EVENT_AUDIO_DELAY:
326 case INPUT_EVENT_SUBTITLE_DELAY:
327 event = new IMEvent( SynchroChanged_Type );
330 case INPUT_EVENT_CACHE:
331 event = new IMEvent( CachingEvent_Type );
334 case INPUT_EVENT_BOOKMARK:
335 event = new IMEvent( BookmarksChanged_Type );
338 case INPUT_EVENT_RECORD:
339 event = new IMEvent( RecordingEvent_Type );
342 case INPUT_EVENT_PROGRAM:
343 /* This is for PID changes */
344 event = new IMEvent( ProgramChanged_Type );
347 case INPUT_EVENT_SIGNAL:
348 /* This is for capture-card signals */
349 /* event = new IMEvent( SignalChanged_Type );
357 QApplication::postEvent( im, event );
361 static int VbiEvent( vlc_object_t *, const char *,
362 vlc_value_t, vlc_value_t, void *param )
364 InputManager *im = (InputManager*)param;
365 IMEvent *event = new IMEvent( ItemTeletextChanged_Type );
367 QApplication::postEvent( im, event );
371 void InputManager::UpdatePosition()
373 /* Update position */
374 int i_length, i_time; /* Int is enough, since we store seconds */
376 i_length = var_GetTime( p_input , "length" ) / 1000000;
377 i_time = var_GetTime( p_input , "time") / 1000000;
378 f_pos = var_GetFloat( p_input , "position" );
379 emit positionUpdated( f_pos, i_time, i_length );
382 void InputManager::UpdateNavigation()
384 /* Update navigation status */
385 vlc_value_t val; val.i_int = 0;
388 var_Change( p_input, "title", VLC_VAR_CHOICESCOUNT, &val, NULL );
392 emit titleChanged( true );
393 msg_Dbg( p_intf, "Title %i", val.i_int );
394 /* p_input != NULL since val.i_int != 0 */
396 var_Change( p_input, "chapter", VLC_VAR_CHOICESCOUNT, &val, NULL );
397 emit chapterChanged( (val.i_int > 0) );
398 msg_Dbg( p_intf, "Chapter: %i", val.i_int );
401 emit titleChanged( false );
404 void InputManager::UpdateStatus()
406 /* Update playing status */
407 int state = var_GetInteger( p_input, "state" );
408 if( i_old_playing_status != state )
410 i_old_playing_status = state;
411 emit statusChanged( state );
415 void InputManager::UpdateRate()
418 int i_new_rate = INPUT_RATE_DEFAULT / var_GetFloat( p_input, "rate" );
419 if( i_new_rate != i_rate )
423 emit rateChanged( i_rate );
427 void InputManager::UpdateName()
429 /* Update text, name and nowplaying */
432 /* Try to get the Title, then the Name */
433 char *psz_name = input_item_GetTitleFbName( input_GetItem( p_input ) );
435 /* Try to get the nowplaying */
436 char *psz_nowplaying =
437 input_item_GetNowPlaying( input_GetItem( p_input ) );
438 if( !EMPTY_STR( psz_nowplaying ) )
440 text.sprintf( "%s - %s", psz_nowplaying, psz_name );
442 else /* Do it ourself */
444 char *psz_artist = input_item_GetArtist( input_GetItem( p_input ) );
446 if( !EMPTY_STR( psz_artist ) )
447 text.sprintf( "%s - %s", psz_artist, psz_name );
449 text.sprintf( "%s", psz_name );
453 /* Free everything */
455 free( psz_nowplaying );
457 /* If we have Nothing */
460 psz_name = input_item_GetURI( input_GetItem( p_input ) );
461 text.sprintf( "%s", psz_name );
462 text = text.remove( 0, text.lastIndexOf( DIR_SEP ) + 1 );
466 if( oldName != text )
468 emit nameChanged( text );
473 bool InputManager::hasAudio()
478 var_Change( p_input, "audio-es", VLC_VAR_CHOICESCOUNT, &val, NULL );
479 return val.i_int > 0;
484 void InputManager::UpdateTeletext()
488 const bool b_enabled = var_CountChoices( p_input, "teletext-es" ) > 0;
489 const int i_teletext_es = var_GetInteger( p_input, "teletext-es" );
491 /* Teletext is possible. Show the buttons */
492 emit teletextPossible( b_enabled );
494 /* If Teletext is selected */
495 if( b_enabled && i_teletext_es >= 0 )
497 /* Then, find the current page */
499 bool b_transparent = false;
501 vlc_object_t *p_vbi = (vlc_object_t *)
502 vlc_object_find_name( p_input, "zvbi", FIND_CHILD );
506 /* We deleted it (if not here, it does not harm), because
507 * var_AddCallback will silently add a duplicated one */
508 var_DelCallback( p_vbi, "vbi-page", VbiEvent, this );
509 /* This callback is not remove explicitly, but interfaces
510 * are guaranted to outlive input */
511 var_AddCallback( p_vbi, "vbi-page", VbiEvent, this );
513 i_page = var_GetInteger( p_vbi, "vbi-page" );
514 b_transparent = !var_GetBool( p_vbi, "vbi-opaque" );
515 vlc_object_release( p_vbi );
517 emit newTelexPageSet( i_page );
518 emit teletextTransparencyActivated( b_transparent );
521 emit teletextActivated( b_enabled && i_teletext_es >= 0 );
525 emit teletextActivated( false );
526 emit teletextPossible( false );
530 void InputManager::UpdateVout()
534 /* Get current vout lists from input */
536 vout_thread_t **pp_vout;
537 if( input_Control( p_input, INPUT_GET_VOUTS, &pp_vout, &i_vout ) )
544 emit voutListChanged( pp_vout, i_vout );
547 bool b_old_video = b_video;
548 b_video = i_vout > 0;
549 if( !!b_old_video != !!b_video )
550 emit voutChanged( b_video );
552 /* Release the vout list */
553 for( int i = 0; i < i_vout; i++ )
554 vlc_object_release( (vlc_object_t*)pp_vout[i] );
558 void InputManager::UpdateAout()
565 void InputManager::UpdateCaching()
567 if(!hasInput()) return;
569 float f_newCache = var_GetFloat ( p_input, "cache" );
570 if( f_newCache != f_cache )
572 f_cache = f_newCache;
574 emit cachingChanged( f_cache );
578 void InputManager::requestArtUpdate()
582 playlist_t *p_playlist = pl_Hold( p_intf );
583 playlist_AskForArtEnqueue( p_playlist, input_GetItem( p_input ), pl_Unlocked );
584 pl_Release( p_intf );
588 /* No input will signal the cover art to update,
589 * let's do it ourself */
594 void InputManager::UpdateArt()
600 char *psz_art = input_item_GetArtURL( input_GetItem( p_input ) );
601 if( psz_art && !strncmp( psz_art, "file://", 7 ) &&
602 decode_URI( psz_art + 7 ) )
604 url = qfu( psz_art + 8 ); // Remove extra / starting on Win32.
606 url = qfu( psz_art + 7 );
610 url = url.replace( "file://", "" );
611 /* Taglib seems to define a attachment://, It won't work yet */
612 url = url.replace( "attachment://", "" );
615 /* Update Art meta */
616 emit artChanged( url );
619 inline void InputManager::UpdateStats()
621 emit statisticsUpdated( input_GetItem( p_input ) );
624 inline void InputManager::UpdateMeta( input_item_t *p_item )
626 emit metaChanged( p_item );
629 inline void InputManager::UpdateMeta()
631 emit currentMetaChanged( input_GetItem( p_input ) );
634 inline void InputManager::UpdateInfo()
636 emit infoChanged( input_GetItem( p_input ) );
639 void InputManager::UpdateRecord()
643 emit recordingStateChanged( var_GetBool( p_input, "record" ) );
647 void InputManager::UpdateProgramEvent()
651 bool b_scrambled = var_GetBool( p_input, "program-scrambled" );
652 emit encryptionChanged( b_scrambled );
656 /* User update of the slider */
657 void InputManager::sliderUpdate( float new_pos )
660 var_SetFloat( p_input, "position", new_pos );
663 /* User togglePlayPause */
664 void InputManager::togglePlayPause()
668 int state = var_GetInteger( p_input, "state" );
669 state = ( state != PLAYING_S ) ? PLAYING_S : PAUSE_S;
670 var_SetInteger( p_input, "state", state );
671 emit statusChanged( state );
675 void InputManager::sectionPrev()
679 int i_type = var_Type( p_input, "next-chapter" );
680 var_TriggerCallback( p_input, (i_type & VLC_VAR_TYPE) != 0 ?
681 "prev-chapter":"prev-title" );
685 void InputManager::sectionNext()
689 int i_type = var_Type( p_input, "next-chapter" );
690 var_TriggerCallback( p_input, (i_type & VLC_VAR_TYPE) != 0 ?
691 "next-chapter":"next-title" );
695 void InputManager::sectionMenu()
699 vlc_value_t val, text;
701 if( var_Change( p_input, "title 0", VLC_VAR_GETLIST, &val, &text ) < 0 )
704 /* XXX is it "Root" or "Title" we want here ?" (set 0 by default) */
706 for( int i = 0; i < val.p_list->i_count; i++ )
708 if( !strcmp( text.p_list->p_values[i].psz_string, "Title" ) )
711 var_FreeList( &val, &text );
713 var_SetInteger( p_input, "title 0", root );
721 /* Set a new Teletext Page */
722 void InputManager::telexSetPage( int page )
726 const int i_teletext_es = var_GetInteger( p_input, "teletext-es" );
728 if( i_teletext_es >= 0 )
730 vlc_object_t *p_vbi = (vlc_object_t *) vlc_object_find_name( p_input,
731 "zvbi", FIND_CHILD );
734 var_SetInteger( p_vbi, "vbi-page", page );
735 vlc_object_release( p_vbi );
736 emit newTelexPageSet( page );
742 /* Set the transparency on teletext */
743 void InputManager::telexSetTransparency( bool b_transparentTelextext )
747 vlc_object_t *p_vbi = (vlc_object_t *) vlc_object_find_name( p_input,
748 "zvbi", FIND_CHILD );
751 var_SetBool( p_vbi, "vbi-opaque", !b_transparentTelextext );
752 vlc_object_release( p_vbi );
753 emit teletextTransparencyActivated( b_transparentTelextext );
758 void InputManager::activateTeletext( bool b_enable )
762 if( hasInput() && !var_Change( p_input, "teletext-es", VLC_VAR_GETLIST, &list, &text ) )
764 if( list.p_list->i_count > 0 )
766 /* Prefer the page 100 if it is present */
768 for( i = 0; i < text.p_list->i_count; i++ )
770 /* The description is the page number as a string */
771 const char *psz_page = text.p_list->p_values[i].psz_string;
772 if( psz_page && !strcmp( psz_page, "100" ) )
775 if( i >= list.p_list->i_count )
777 var_SetInteger( p_input, "spu-es", b_enable ? list.p_list->p_values[i].i_int : -1 );
779 var_FreeList( &list, &text );
783 void InputManager::reverse()
787 float f_rate = var_GetFloat( p_input, "rate" );
788 var_SetFloat( p_input, "rate", -f_rate );
792 void InputManager::slower()
795 var_TriggerCallback( p_input, "rate-slower" );
798 void InputManager::faster()
801 var_TriggerCallback( p_input, "rate-faster" );
804 void InputManager::littlefaster()
806 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_RATE_FASTER_FINE );
809 void InputManager::littleslower()
811 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_RATE_SLOWER_FINE );
814 void InputManager::normalRate()
817 var_SetFloat( p_input, "rate", 1. );
820 void InputManager::setRate( int new_rate )
823 var_SetFloat( p_input, "rate",
824 (float)INPUT_RATE_DEFAULT / (float)new_rate );
827 void InputManager::jumpFwd()
829 int i_interval = config_GetInt( p_input, "short-jump-size" );
832 mtime_t val = (mtime_t)(i_interval) * 1000000L;
833 var_SetTime( p_input, "time-offset", val );
837 void InputManager::jumpBwd()
839 int i_interval = config_GetInt( p_input, "short-jump-size" );
842 mtime_t val = -1 *(mtime_t)(i_interval) * 1000000L;
843 var_SetTime( p_input, "time-offset", val );
847 void InputManager::setAtoB()
851 timeA = var_GetTime( THEMIM->getInput(), "time" );
855 timeB = var_GetTime( THEMIM->getInput(), "time" );
856 var_SetTime( THEMIM->getInput(), "time" , timeA );
857 CONNECT( this, positionUpdated( float, int, int ),
858 this, AtoBLoop( float, int, int ) );
864 disconnect( this, SIGNAL( positionUpdated( float, int, int ) ),
865 this, SLOT( AtoBLoop( float, int, int ) ) );
867 emit AtoBchanged( (timeA != 0 ), (timeB != 0 ) );
870 /* Function called regularly when in an AtoB loop */
871 void InputManager::AtoBLoop( float, int i_time, int )
875 if( ( i_time >= (int)( timeB/1000000 ) )
876 || ( i_time < (int)( timeA/1000000 ) ) )
877 var_SetTime( THEMIM->getInput(), "time" , timeA );
881 /**********************************************************************
882 * MainInputManager implementation. Wrap an input manager and
883 * take care of updating the main playlist input.
884 * Used in the main playlist Dialog
885 **********************************************************************/
886 MainInputManager * MainInputManager::instance = NULL;
888 MainInputManager::MainInputManager( intf_thread_t *_p_intf )
889 : QObject(NULL), p_intf( _p_intf )
892 im = new InputManager( this, p_intf );
894 var_AddCallback( THEPL, "item-change", ItemChanged, im );
895 var_AddCallback( THEPL, "item-current", PLItemChanged, this );
896 var_AddCallback( THEPL, "activity", PLItemChanged, this );
897 var_AddCallback( THEPL, "playlist-item-append", PLItemAppended, this );
898 var_AddCallback( THEPL, "playlist-item-deleted", PLItemRemoved, this );
899 var_AddCallback( THEPL, "random", RandomChanged, this );
900 var_AddCallback( THEPL, "repeat", RepeatChanged, this );
901 var_AddCallback( THEPL, "loop", LoopChanged, this );
903 var_AddCallback( p_intf->p_libvlc, "volume-change", VolumeChanged, this );
905 /* Warn our embedded IM about input changes */
906 CONNECT( this, inputChanged( input_thread_t * ),
907 im, setInput( input_thread_t * ) );
909 /* emit check if playlist has already started playing */
910 input_thread_t *p_input = playlist_CurrentInput( THEPL );
913 input_item_t *p_item = input_GetItem( p_input );
916 IMEvent *event = new IMEvent( ItemChanged_Type, p_item );
917 customEvent( event );
920 vlc_object_release( p_input );
924 MainInputManager::~MainInputManager()
928 emit inputChanged( NULL );
929 var_DelCallback( p_input, "state", PLItemChanged, this );
930 vlc_object_release( p_input );
933 var_DelCallback( p_intf->p_libvlc, "volume-change", VolumeChanged, this );
935 var_DelCallback( THEPL, "activity", PLItemChanged, this );
936 var_DelCallback( THEPL, "item-change", ItemChanged, im );
938 var_DelCallback( THEPL, "item-current", PLItemChanged, this );
939 var_DelCallback( THEPL, "playlist-item-append", PLItemAppended, this );
940 var_DelCallback( THEPL, "playlist-item-deleted", PLItemRemoved, this );
941 var_DelCallback( THEPL, "random", RandomChanged, this );
942 var_DelCallback( THEPL, "repeat", RepeatChanged, this );
943 var_DelCallback( THEPL, "loop", LoopChanged, this );
947 vout_thread_t* MainInputManager::getVout()
949 return p_input ? input_GetVout( p_input ) : NULL;
952 aout_instance_t * MainInputManager::getAout()
954 return p_input ? input_GetAout( p_input ) : NULL;
957 void MainInputManager::customEvent( QEvent *event )
959 int type = event->type();
963 // msg_Dbg( p_intf, "New MainIM Event of type: %i", type );
966 case VolumeChanged_Type:
967 emit volumeChanged();
969 case PLItemAppended_Type:
970 plEv = static_cast<PLEvent*>( event );
971 emit playlistItemAppended( plEv->i_item, plEv->i_parent );
973 case PLItemRemoved_Type:
974 plEv = static_cast<PLEvent*>( event );
975 emit playlistItemRemoved( plEv->i_item );
977 case RandomChanged_Type:
978 emit randomChanged( var_GetBool( THEPL, "random" ) );
980 case LoopChanged_Type:
981 case RepeatChanged_Type:
985 if( type != ItemChanged_Type ) return;
988 /* Should be PLItemChanged Event */
989 if( !p_intf->p_sys->b_isDialogProvider )
991 if( p_input && ( p_input->b_dead || !vlc_object_alive (p_input) ) )
993 emit inputChanged( p_input );
994 var_DelCallback( p_input, "state", PLItemChanged, this );
995 vlc_object_release( p_input );
1002 p_input = playlist_CurrentInput(THEPL);
1005 var_AddCallback( p_input, "state", PLItemChanged, this );
1006 emit inputChanged( p_input );
1012 /* remove previous stored p_input */
1015 vlc_object_release( p_input );
1018 /* we are working as a dialogs provider */
1019 playlist_t *p_playlist = pl_Hold( p_intf );
1020 p_input = playlist_CurrentInput( p_playlist );
1023 emit inputChanged( p_input );
1025 pl_Release( p_intf );
1029 /* Playlist Control functions */
1030 void MainInputManager::stop()
1032 playlist_Stop( THEPL );
1035 void MainInputManager::next()
1037 playlist_Next( THEPL );
1040 void MainInputManager::prev()
1042 playlist_Prev( THEPL );
1045 void MainInputManager::togglePlayPause()
1047 /* No input, play */
1049 playlist_Play( THEPL );
1051 getIM()->togglePlayPause();
1054 void MainInputManager::toggleRandom()
1056 var_ToggleBool( THEPL, "random" );
1059 void MainInputManager::notifyRepeatLoop()
1061 int i_value = var_GetBool( THEPL, "loop" ) * REPEAT_ONE
1062 + var_GetBool( THEPL, "repeat" ) * REPEAT_ALL;
1064 emit repeatLoopChanged( i_value );
1067 void MainInputManager::loopRepeatLoopStatus()
1069 /* Toggle Normal -> Loop -> Repeat -> Normal ... */
1070 if( var_GetBool( THEPL, "repeat" ) )
1071 var_SetBool( THEPL, "repeat", false );
1072 else if( var_GetBool( THEPL, "loop" ) )
1074 var_SetBool( THEPL, "loop", false );
1075 var_SetBool( THEPL, "repeat", true );
1078 var_SetBool( THEPL, "loop", true );
1081 void MainInputManager::activatePlayQuit( bool b_exit )
1083 var_SetBool( THEPL, "play-and-exit", b_exit );
1087 /****************************
1088 * Static callbacks for MIM *
1089 ****************************/
1090 static int PLItemChanged( vlc_object_t *p_this, const char *psz_var,
1091 vlc_value_t oldval, vlc_value_t, void *param )
1093 MainInputManager *mim = (MainInputManager*)param;
1095 IMEvent *event = new IMEvent( ItemChanged_Type );
1096 QApplication::postEvent( mim, event );
1100 static int VolumeChanged( vlc_object_t *p_this, const char *psz_var,
1101 vlc_value_t oldval, vlc_value_t newval, void *param )
1103 MainInputManager *mim = (MainInputManager*)param;
1105 IMEvent *event = new IMEvent( VolumeChanged_Type );
1106 QApplication::postEvent( mim, event );
1110 static int PLItemAppended
1111 ( vlc_object_t * obj, const char *var, vlc_value_t old, vlc_value_t cur, void *data )
1113 MainInputManager *mim = static_cast<MainInputManager*>(data);
1114 playlist_add_t *p_add = static_cast<playlist_add_t*>( cur.p_address );
1116 PLEvent *event = new PLEvent( PLItemAppended_Type, p_add->i_item, p_add->i_node );
1117 QApplication::postEvent( mim, event );
1120 static int PLItemRemoved
1121 ( vlc_object_t * obj, const char *var, vlc_value_t old, vlc_value_t cur, void *data )
1123 MainInputManager *mim = static_cast<MainInputManager*>(data);
1125 PLEvent *event = new PLEvent( PLItemRemoved_Type, cur.i_int, 0 );
1126 QApplication::postEvent( mim, event );
1130 static int RandomChanged
1131 ( vlc_object_t * obj, const char *var, vlc_value_t old, vlc_value_t cur, void *data )
1133 MainInputManager *mim = static_cast<MainInputManager*>(data);
1135 IMEvent *event = new IMEvent( RandomChanged_Type );
1136 QApplication::postEvent( mim, event );
1140 /* Probably could be merged with next callback */
1141 static int LoopChanged
1142 ( vlc_object_t * obj, const char *var, vlc_value_t old, vlc_value_t cur, void *data )
1144 MainInputManager *mim = static_cast<MainInputManager*>(data);
1146 IMEvent *event = new IMEvent( LoopChanged_Type );
1147 QApplication::postEvent( mim, event );
1151 static int RepeatChanged
1152 ( vlc_object_t * obj, const char *var, vlc_value_t old, vlc_value_t cur, void *data )
1154 MainInputManager *mim = static_cast<MainInputManager*>(data);
1156 IMEvent *event = new IMEvent( RepeatChanged_Type );
1157 QApplication::postEvent( mim, event );