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 * );
48 static int SoundMuteChanged( vlc_object_t *, const char *,
49 vlc_value_t, vlc_value_t, void * );
51 static int RandomChanged( vlc_object_t *, const char *,
52 vlc_value_t, vlc_value_t, void * );
53 static int LoopChanged( vlc_object_t *, const char *,
54 vlc_value_t, vlc_value_t, void * );
55 static int RepeatChanged( vlc_object_t *, const char *,
56 vlc_value_t, vlc_value_t, void * );
59 static int InputEvent( vlc_object_t *, const char *,
60 vlc_value_t, vlc_value_t, void * );
61 static int VbiEvent( vlc_object_t *, const char *,
62 vlc_value_t, vlc_value_t, void * );
65 /**********************************************************************
66 * InputManager implementation
67 **********************************************************************
68 * The Input Manager can be the main one around the playlist
69 * But can also be used for VLM dialog or similar
70 **********************************************************************/
72 InputManager::InputManager( QObject *parent, intf_thread_t *_p_intf) :
73 QObject( parent ), p_intf( _p_intf )
75 i_old_playing_status = END_S;
85 f_cache = -1.; /* impossible initial value, different from all */
88 InputManager::~InputManager()
93 /* Define the Input used.
94 Add the callbacks on input
95 p_input is held once here */
96 void InputManager::setInput( input_thread_t *_p_input )
100 if( p_input && !( p_input->b_dead || !vlc_object_alive (p_input) ) )
102 msg_Dbg( p_intf, "IM: Setting an input" );
103 vlc_object_hold( p_input );
104 emit statusChanged( PLAYING_S );
111 p_item = input_GetItem( p_input );
117 assert( !p_input_vbi );
118 emit rateChanged( INPUT_RATE_DEFAULT );
122 /* delete Input if it ever existed.
123 Delete the callbacls on input
124 p_input is released once here */
125 void InputManager::delInput()
127 if( !p_input ) return;
128 msg_Dbg( p_intf, "IM: Deleting the input" );
131 i_old_playing_status = END_S;
141 vlc_object_release( p_input_vbi );
145 vlc_object_release( p_input );
148 emit positionUpdated( -1.0, 0 ,0 );
149 emit rateChanged( INPUT_RATE_DEFAULT ); /* TODO: Do we want this ? */
150 emit nameChanged( "" );
151 emit chapterChanged( 0 );
152 emit titleChanged( 0 );
153 emit statusChanged( END_S );
155 emit teletextPossible( false );
156 emit AtoBchanged( false, false );
157 emit voutChanged( false );
158 emit voutListChanged( NULL, 0 );
160 /* Reset all InfoPanels but stats */
161 emit artChanged( NULL );
162 emit infoChanged( NULL );
163 emit currentMetaChanged( (input_item_t *)NULL );
165 emit encryptionChanged( false );
166 emit recordingStateChanged( false );
169 /* Convert the event from the callbacks in actions */
170 void InputManager::customEvent( QEvent *event )
172 int i_type = event->type();
173 IMEvent *ple = static_cast<IMEvent *>(event);
175 if( i_type == ItemChanged_Type )
176 UpdateMeta( ple->p_item );
184 case PositionUpdate_Type:
187 case StatisticsUpdate_Type:
190 case ItemChanged_Type:
191 /* Ignore ItemChanged_Type event that does not apply to our input */
192 if( p_item == ple->p_item )
197 /* Update duration of file */
200 case ItemStateChanged_Type:
201 // TODO: Fusion with above state
204 // UpdateNavigation(); This shouldn't be useful now
205 // UpdateTeletext(); Same
207 case NameChanged_Type:
210 case MetaChanged_Type:
212 UpdateName(); /* Needed for NowPlaying */
213 UpdateArt(); /* Art is part of meta in the core */
215 case InfoChanged_Type:
218 case ItemTitleChanged_Type:
220 UpdateName(); /* Display the name of the Chapter, if exists */
222 case ItemRateChanged_Type:
225 case ItemEsChanged_Type:
227 // We don't do anything ES related. Why ?
229 case ItemTeletextChanged_Type:
232 case InterfaceVoutUpdate_Type:
235 case SynchroChanged_Type:
236 emit synchroChanged();
238 case CachingEvent_Type:
241 case BookmarksChanged_Type:
242 emit bookmarksChanged();
244 case InterfaceAoutUpdate_Type:
247 case RecordingEvent_Type:
250 case ProgramChanged_Type:
251 UpdateProgramEvent();
254 msg_Warn( p_intf, "This shouldn't happen: %i", i_type );
259 /* Add the callbacks on Input. Self explanatory */
260 inline void InputManager::addCallbacks()
262 var_AddCallback( p_input, "intf-event", InputEvent, this );
265 /* Delete the callbacks on Input. Self explanatory */
266 inline void InputManager::delCallbacks()
268 var_DelCallback( p_input, "intf-event", InputEvent, this );
271 /* Static callbacks for IM */
272 static int ItemChanged( vlc_object_t *p_this, const char *psz_var,
273 vlc_value_t oldval, vlc_value_t newval, void *param )
275 InputManager *im = (InputManager*)param;
276 input_item_t *p_item = static_cast<input_item_t *>(newval.p_address);
278 IMEvent *event = new IMEvent( ItemChanged_Type, p_item );
279 QApplication::postEvent( im, event );
283 static int InputEvent( vlc_object_t *p_this, const char *,
284 vlc_value_t, vlc_value_t newval, void *param )
286 InputManager *im = (InputManager*)param;
289 switch( newval.i_int )
291 case INPUT_EVENT_STATE:
292 event = new IMEvent( ItemStateChanged_Type );
294 case INPUT_EVENT_RATE:
295 event = new IMEvent( ItemRateChanged_Type );
297 case INPUT_EVENT_POSITION:
298 //case INPUT_EVENT_LENGTH:
299 event = new IMEvent( PositionUpdate_Type );
302 case INPUT_EVENT_TITLE:
303 case INPUT_EVENT_CHAPTER:
304 event = new IMEvent( ItemTitleChanged_Type );
308 event = new IMEvent( ItemEsChanged_Type );
310 case INPUT_EVENT_TELETEXT:
311 event = new IMEvent( ItemTeletextChanged_Type );
314 case INPUT_EVENT_STATISTICS:
315 event = new IMEvent( StatisticsUpdate_Type );
318 case INPUT_EVENT_VOUT:
319 event = new IMEvent( InterfaceVoutUpdate_Type );
321 case INPUT_EVENT_AOUT:
322 event = new IMEvent( InterfaceAoutUpdate_Type );
325 case INPUT_EVENT_ITEM_META: /* Codec MetaData + Art */
326 event = new IMEvent( MetaChanged_Type );
328 case INPUT_EVENT_ITEM_INFO: /* Codec Info */
329 event = new IMEvent( InfoChanged_Type );
331 case INPUT_EVENT_ITEM_NAME:
332 event = new IMEvent( NameChanged_Type );
335 case INPUT_EVENT_AUDIO_DELAY:
336 case INPUT_EVENT_SUBTITLE_DELAY:
337 event = new IMEvent( SynchroChanged_Type );
340 case INPUT_EVENT_CACHE:
341 event = new IMEvent( CachingEvent_Type );
344 case INPUT_EVENT_BOOKMARK:
345 event = new IMEvent( BookmarksChanged_Type );
348 case INPUT_EVENT_RECORD:
349 event = new IMEvent( RecordingEvent_Type );
352 case INPUT_EVENT_PROGRAM:
353 /* This is for PID changes */
354 event = new IMEvent( ProgramChanged_Type );
357 case INPUT_EVENT_SIGNAL:
358 /* This is for capture-card signals */
359 /* event = new IMEvent( SignalChanged_Type );
367 QApplication::postEvent( im, event );
371 static int VbiEvent( vlc_object_t *, const char *,
372 vlc_value_t, vlc_value_t, void *param )
374 InputManager *im = (InputManager*)param;
375 IMEvent *event = new IMEvent( ItemTeletextChanged_Type );
377 QApplication::postEvent( im, event );
381 void InputManager::UpdatePosition()
383 /* Update position */
387 i_length = var_GetTime( p_input , "length" ) / 1000000;
388 i_time = var_GetTime( p_input , "time");
389 f_pos = var_GetFloat( p_input , "position" );
390 emit positionUpdated( f_pos, i_time, i_length );
393 void InputManager::UpdateNavigation()
395 /* Update navigation status */
396 vlc_value_t val; val.i_int = 0;
399 var_Change( p_input, "title", VLC_VAR_CHOICESCOUNT, &val, NULL );
403 emit titleChanged( true );
404 msg_Dbg( p_intf, "Title %i", val.i_int );
405 /* p_input != NULL since val.i_int != 0 */
407 var_Change( p_input, "chapter", VLC_VAR_CHOICESCOUNT, &val, NULL );
408 emit chapterChanged( (val.i_int > 0) );
409 msg_Dbg( p_intf, "Chapter: %i", val.i_int );
412 emit titleChanged( false );
415 void InputManager::UpdateStatus()
417 /* Update playing status */
418 int state = var_GetInteger( p_input, "state" );
419 if( i_old_playing_status != state )
421 i_old_playing_status = state;
422 emit statusChanged( state );
426 void InputManager::UpdateRate()
429 int i_new_rate = INPUT_RATE_DEFAULT / var_GetFloat( p_input, "rate" );
430 if( i_new_rate != i_rate )
434 emit rateChanged( i_rate );
438 void InputManager::UpdateName()
440 /* Update text, name and nowplaying */
443 /* Try to get the Title, then the Name */
444 char *psz_name = input_item_GetTitleFbName( input_GetItem( p_input ) );
446 /* Try to get the nowplaying */
447 char *psz_nowplaying =
448 input_item_GetNowPlaying( input_GetItem( p_input ) );
449 if( !EMPTY_STR( psz_nowplaying ) )
451 text.sprintf( "%s - %s", psz_nowplaying, psz_name );
453 else /* Do it ourself */
455 char *psz_artist = input_item_GetArtist( input_GetItem( p_input ) );
457 if( !EMPTY_STR( psz_artist ) )
458 text.sprintf( "%s - %s", psz_artist, psz_name );
460 text.sprintf( "%s", psz_name );
464 /* Free everything */
466 free( psz_nowplaying );
468 /* If we have Nothing */
471 psz_name = input_item_GetURI( input_GetItem( p_input ) );
472 text.sprintf( "%s", psz_name );
473 text = text.remove( 0, text.lastIndexOf( DIR_SEP ) + 1 );
477 if( oldName != text )
479 emit nameChanged( text );
484 bool InputManager::hasAudio()
489 var_Change( p_input, "audio-es", VLC_VAR_CHOICESCOUNT, &val, NULL );
490 return val.i_int > 0;
495 void InputManager::UpdateTeletext()
499 const bool b_enabled = var_CountChoices( p_input, "teletext-es" ) > 0;
500 const int i_teletext_es = var_GetInteger( p_input, "teletext-es" );
502 /* Teletext is possible. Show the buttons */
503 emit teletextPossible( b_enabled );
505 /* If Teletext is selected */
506 if( b_enabled && i_teletext_es >= 0 )
508 /* Then, find the current page */
510 bool b_transparent = false;
514 var_DelCallback( p_input_vbi, "vbi-page", VbiEvent, this );
515 vlc_object_release( p_input_vbi );
517 p_input_vbi = (vlc_object_t *)
518 vlc_object_find_name( p_input, "zvbi", FIND_CHILD );
522 /* This callback is not remove explicitly, but interfaces
523 * are guaranted to outlive input */
524 var_AddCallback( p_input_vbi, "vbi-page", VbiEvent, this );
526 i_page = var_GetInteger( p_input_vbi, "vbi-page" );
527 b_transparent = !var_GetBool( p_input_vbi, "vbi-opaque" );
529 emit newTelexPageSet( i_page );
530 emit teletextTransparencyActivated( b_transparent );
533 emit teletextActivated( b_enabled && i_teletext_es >= 0 );
537 emit teletextActivated( false );
538 emit teletextPossible( false );
542 void InputManager::UpdateVout()
546 /* Get current vout lists from input */
548 vout_thread_t **pp_vout;
549 if( input_Control( p_input, INPUT_GET_VOUTS, &pp_vout, &i_vout ) )
556 emit voutListChanged( pp_vout, i_vout );
559 bool b_old_video = b_video;
560 b_video = i_vout > 0;
561 if( !!b_old_video != !!b_video )
562 emit voutChanged( b_video );
564 /* Release the vout list */
565 for( int i = 0; i < i_vout; i++ )
566 vlc_object_release( (vlc_object_t*)pp_vout[i] );
570 void InputManager::UpdateAout()
577 void InputManager::UpdateCaching()
579 if(!hasInput()) return;
581 float f_newCache = var_GetFloat ( p_input, "cache" );
582 if( f_newCache != f_cache )
584 f_cache = f_newCache;
586 emit cachingChanged( f_cache );
590 void InputManager::requestArtUpdate()
594 playlist_t *p_playlist = pl_Hold( p_intf );
595 playlist_AskForArtEnqueue( p_playlist, input_GetItem( p_input ), pl_Unlocked );
596 pl_Release( p_intf );
600 /* No input will signal the cover art to update,
601 * let's do it ourself */
606 const QString InputManager::decodeArtURL( input_item_t *p_item )
610 char *psz_art = input_item_GetArtURL( p_item );
612 if( psz_art && !strncmp( psz_art, "file://", 7 ) &&
613 decode_URI( psz_art + 7 ) )
615 url = qfu( psz_art + 8 ); // Remove extra / starting on Win32.
617 url = qfu( psz_art + 7 );
621 url = url.replace( "file://", "" );
622 /* Taglib seems to define a attachment://, It won't work yet */
623 url = url.replace( "attachment://", "" );
627 void InputManager::UpdateArt()
632 url = decodeArtURL( input_GetItem( p_input ) );
634 /* the art hasn't changed, no need to update */
638 /* Update Art meta */
640 emit artChanged( artUrl );
643 inline void InputManager::UpdateStats()
645 emit statisticsUpdated( input_GetItem( p_input ) );
648 inline void InputManager::UpdateMeta( input_item_t *p_item )
650 emit metaChanged( p_item );
653 inline void InputManager::UpdateMeta()
655 emit currentMetaChanged( input_GetItem( p_input ) );
658 inline void InputManager::UpdateInfo()
660 emit infoChanged( input_GetItem( p_input ) );
663 void InputManager::UpdateRecord()
667 emit recordingStateChanged( var_GetBool( p_input, "record" ) );
671 void InputManager::UpdateProgramEvent()
675 bool b_scrambled = var_GetBool( p_input, "program-scrambled" );
676 emit encryptionChanged( b_scrambled );
680 /* User update of the slider */
681 void InputManager::sliderUpdate( float new_pos )
684 var_SetFloat( p_input, "position", new_pos );
687 /* User togglePlayPause */
688 void InputManager::togglePlayPause()
692 int state = var_GetInteger( p_input, "state" );
693 state = ( state != PLAYING_S ) ? PLAYING_S : PAUSE_S;
694 var_SetInteger( p_input, "state", state );
695 emit statusChanged( state );
699 void InputManager::sectionPrev()
703 int i_type = var_Type( p_input, "next-chapter" );
704 var_TriggerCallback( p_input, (i_type & VLC_VAR_TYPE) != 0 ?
705 "prev-chapter":"prev-title" );
709 void InputManager::sectionNext()
713 int i_type = var_Type( p_input, "next-chapter" );
714 var_TriggerCallback( p_input, (i_type & VLC_VAR_TYPE) != 0 ?
715 "next-chapter":"next-title" );
719 void InputManager::sectionMenu()
723 vlc_value_t val, text;
725 if( var_Change( p_input, "title 0", VLC_VAR_GETLIST, &val, &text ) < 0 )
728 /* XXX is it "Root" or "Title" we want here ?" (set 0 by default) */
730 for( int i = 0; i < val.p_list->i_count; i++ )
732 if( !strcmp( text.p_list->p_values[i].psz_string, "Title" ) )
735 var_FreeList( &val, &text );
737 var_SetInteger( p_input, "title 0", root );
745 /* Set a new Teletext Page */
746 void InputManager::telexSetPage( int page )
748 if( hasInput() && p_input_vbi )
750 const int i_teletext_es = var_GetInteger( p_input, "teletext-es" );
752 if( i_teletext_es >= 0 )
754 var_SetInteger( p_input_vbi, "vbi-page", page );
755 emit newTelexPageSet( page );
760 /* Set the transparency on teletext */
761 void InputManager::telexSetTransparency( bool b_transparentTelextext )
763 if( hasInput() && p_input_vbi )
765 var_SetBool( p_input_vbi, "vbi-opaque", !b_transparentTelextext );
766 emit teletextTransparencyActivated( b_transparentTelextext );
770 void InputManager::activateTeletext( bool b_enable )
774 if( hasInput() && !var_Change( p_input, "teletext-es", VLC_VAR_GETLIST, &list, &text ) )
776 if( list.p_list->i_count > 0 )
778 /* Prefer the page 100 if it is present */
780 for( i = 0; i < text.p_list->i_count; i++ )
782 /* The description is the page number as a string */
783 const char *psz_page = text.p_list->p_values[i].psz_string;
784 if( psz_page && !strcmp( psz_page, "100" ) )
787 if( i >= list.p_list->i_count )
789 var_SetInteger( p_input, "spu-es", b_enable ? list.p_list->p_values[i].i_int : -1 );
791 var_FreeList( &list, &text );
795 void InputManager::reverse()
799 float f_rate = var_GetFloat( p_input, "rate" );
800 var_SetFloat( p_input, "rate", -f_rate );
804 void InputManager::slower()
807 var_TriggerCallback( p_input, "rate-slower" );
810 void InputManager::faster()
813 var_TriggerCallback( p_input, "rate-faster" );
816 void InputManager::littlefaster()
818 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_RATE_FASTER_FINE );
821 void InputManager::littleslower()
823 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_RATE_SLOWER_FINE );
826 void InputManager::normalRate()
829 var_SetFloat( p_input, "rate", 1. );
832 void InputManager::setRate( int new_rate )
835 var_SetFloat( p_input, "rate",
836 (float)INPUT_RATE_DEFAULT / (float)new_rate );
839 void InputManager::jumpFwd()
841 int i_interval = var_InheritInteger( p_input, "short-jump-size" );
844 mtime_t val = (mtime_t)(i_interval) * 1000000L;
845 var_SetTime( p_input, "time-offset", val );
849 void InputManager::jumpBwd()
851 int i_interval = var_InheritInteger( p_input, "short-jump-size" );
854 mtime_t val = -1 *(mtime_t)(i_interval) * 1000000L;
855 var_SetTime( p_input, "time-offset", val );
859 void InputManager::setAtoB()
863 timeA = var_GetTime( THEMIM->getInput(), "time" );
867 timeB = var_GetTime( THEMIM->getInput(), "time" );
868 var_SetTime( THEMIM->getInput(), "time" , timeA );
869 CONNECT( this, positionUpdated( float, int64_t, int ),
870 this, AtoBLoop( float, int64_t, int ) );
876 disconnect( this, SIGNAL( positionUpdated( float, int64_t, int ) ),
877 this, SLOT( AtoBLoop( float, int64_t, int ) ) );
879 emit AtoBchanged( (timeA != 0 ), (timeB != 0 ) );
882 /* Function called regularly when in an AtoB loop */
883 void InputManager::AtoBLoop( float, int64_t i_time, int )
887 if( i_time >= timeB || i_time < timeA )
888 var_SetTime( THEMIM->getInput(), "time" , timeA );
892 /**********************************************************************
893 * MainInputManager implementation. Wrap an input manager and
894 * take care of updating the main playlist input.
895 * Used in the main playlist Dialog
896 **********************************************************************/
897 MainInputManager * MainInputManager::instance = NULL;
899 MainInputManager::MainInputManager( intf_thread_t *_p_intf )
900 : QObject(NULL), p_intf( _p_intf )
903 im = new InputManager( this, p_intf );
905 var_AddCallback( THEPL, "item-change", ItemChanged, im );
906 var_AddCallback( THEPL, "item-current", PLItemChanged, this );
907 var_AddCallback( THEPL, "activity", PLItemChanged, this );
908 var_AddCallback( THEPL, "playlist-item-append", PLItemAppended, this );
909 var_AddCallback( THEPL, "playlist-item-deleted", PLItemRemoved, this );
910 var_AddCallback( THEPL, "random", RandomChanged, this );
911 var_AddCallback( THEPL, "repeat", RepeatChanged, this );
912 var_AddCallback( THEPL, "loop", LoopChanged, this );
914 var_AddCallback( p_intf->p_libvlc, "volume-change", VolumeChanged, this );
915 var_AddCallback( p_intf->p_libvlc, "volume-muted", SoundMuteChanged, this );
917 /* Warn our embedded IM about input changes */
918 CONNECT( this, inputChanged( input_thread_t * ),
919 im, setInput( input_thread_t * ) );
921 /* emit check if playlist has already started playing */
922 input_thread_t *p_input = playlist_CurrentInput( THEPL );
925 input_item_t *p_item = input_GetItem( p_input );
928 IMEvent *event = new IMEvent( ItemChanged_Type, p_item );
929 customEvent( event );
932 vlc_object_release( p_input );
936 MainInputManager::~MainInputManager()
940 emit inputChanged( NULL );
941 var_DelCallback( p_input, "state", PLItemChanged, this );
942 vlc_object_release( p_input );
945 var_DelCallback( p_intf->p_libvlc, "volume-change", VolumeChanged, this );
946 var_DelCallback( p_intf->p_libvlc, "volume-muted", SoundMuteChanged, this );
948 var_DelCallback( THEPL, "activity", PLItemChanged, this );
949 var_DelCallback( THEPL, "item-change", ItemChanged, im );
951 var_DelCallback( THEPL, "item-current", PLItemChanged, this );
952 var_DelCallback( THEPL, "playlist-item-append", PLItemAppended, this );
953 var_DelCallback( THEPL, "playlist-item-deleted", PLItemRemoved, this );
954 var_DelCallback( THEPL, "random", RandomChanged, this );
955 var_DelCallback( THEPL, "repeat", RepeatChanged, this );
956 var_DelCallback( THEPL, "loop", LoopChanged, this );
960 vout_thread_t* MainInputManager::getVout()
962 return p_input ? input_GetVout( p_input ) : NULL;
965 aout_instance_t * MainInputManager::getAout()
967 return p_input ? input_GetAout( p_input ) : NULL;
970 void MainInputManager::customEvent( QEvent *event )
972 int type = event->type();
976 // msg_Dbg( p_intf, "New MainIM Event of type: %i", type );
979 case VolumeChanged_Type:
980 emit volumeChanged();
982 case SoundMuteChanged_Type:
983 emit soundMuteChanged();
985 case PLItemAppended_Type:
986 plEv = static_cast<PLEvent*>( event );
987 emit playlistItemAppended( plEv->i_item, plEv->i_parent );
989 case PLItemRemoved_Type:
990 plEv = static_cast<PLEvent*>( event );
991 emit playlistItemRemoved( plEv->i_item );
993 case RandomChanged_Type:
994 emit randomChanged( var_GetBool( THEPL, "random" ) );
996 case LoopChanged_Type:
997 case RepeatChanged_Type:
1001 if( type != ItemChanged_Type ) return;
1004 /* Should be PLItemChanged Event */
1005 if( !p_intf->p_sys->b_isDialogProvider )
1007 if( p_input && ( p_input->b_dead || !vlc_object_alive (p_input) ) )
1009 emit inputChanged( p_input );
1010 var_DelCallback( p_input, "state", PLItemChanged, this );
1011 vlc_object_release( p_input );
1018 p_input = playlist_CurrentInput(THEPL);
1021 var_AddCallback( p_input, "state", PLItemChanged, this );
1022 emit inputChanged( p_input );
1028 /* remove previous stored p_input */
1031 vlc_object_release( p_input );
1034 /* we are working as a dialogs provider */
1035 playlist_t *p_playlist = pl_Hold( p_intf );
1036 p_input = playlist_CurrentInput( p_playlist );
1039 emit inputChanged( p_input );
1041 pl_Release( p_intf );
1045 /* Playlist Control functions */
1046 void MainInputManager::stop()
1048 playlist_Stop( THEPL );
1051 void MainInputManager::next()
1053 playlist_Next( THEPL );
1056 void MainInputManager::prev()
1058 playlist_Prev( THEPL );
1061 void MainInputManager::togglePlayPause()
1063 /* No input, play */
1065 playlist_Play( THEPL );
1067 getIM()->togglePlayPause();
1070 void MainInputManager::play()
1072 /* No input, play */
1074 playlist_Play( THEPL );
1077 if( PLAYING_S != var_GetInteger( p_input, "state" ) )
1079 getIM()->togglePlayPause();
1084 void MainInputManager::pause()
1086 if(p_input && PLAYING_S == var_GetInteger( p_input, "state" ) )
1088 getIM()->togglePlayPause();
1092 void MainInputManager::toggleRandom()
1094 var_ToggleBool( THEPL, "random" );
1097 void MainInputManager::notifyRepeatLoop()
1099 int i_value = var_GetBool( THEPL, "loop" ) * REPEAT_ONE
1100 + var_GetBool( THEPL, "repeat" ) * REPEAT_ALL;
1102 emit repeatLoopChanged( i_value );
1105 void MainInputManager::loopRepeatLoopStatus()
1107 /* Toggle Normal -> Loop -> Repeat -> Normal ... */
1108 if( var_GetBool( THEPL, "repeat" ) )
1109 var_SetBool( THEPL, "repeat", false );
1110 else if( var_GetBool( THEPL, "loop" ) )
1112 var_SetBool( THEPL, "loop", false );
1113 var_SetBool( THEPL, "repeat", true );
1116 var_SetBool( THEPL, "loop", true );
1119 void MainInputManager::activatePlayQuit( bool b_exit )
1121 var_SetBool( THEPL, "play-and-exit", b_exit );
1125 /****************************
1126 * Static callbacks for MIM *
1127 ****************************/
1128 static int PLItemChanged( vlc_object_t *p_this, const char *psz_var,
1129 vlc_value_t oldval, vlc_value_t, void *param )
1131 MainInputManager *mim = (MainInputManager*)param;
1133 IMEvent *event = new IMEvent( ItemChanged_Type );
1134 QApplication::postEvent( mim, event );
1138 static int VolumeChanged( vlc_object_t *p_this, const char *psz_var,
1139 vlc_value_t oldval, vlc_value_t newval, void *param )
1141 MainInputManager *mim = (MainInputManager*)param;
1143 IMEvent *event = new IMEvent( VolumeChanged_Type );
1144 QApplication::postEvent( mim, event );
1148 static int SoundMuteChanged( vlc_object_t *p_this, const char *psz_var,
1149 vlc_value_t oldval, vlc_value_t newval, void *param )
1151 MainInputManager *mim = (MainInputManager*)param;
1153 IMEvent *event = new IMEvent( SoundMuteChanged_Type );
1154 QApplication::postEvent( mim, event );
1158 static int PLItemAppended
1159 ( vlc_object_t * obj, const char *var, vlc_value_t old, vlc_value_t cur, void *data )
1161 MainInputManager *mim = static_cast<MainInputManager*>(data);
1162 playlist_add_t *p_add = static_cast<playlist_add_t*>( cur.p_address );
1164 PLEvent *event = new PLEvent( PLItemAppended_Type, p_add->i_item, p_add->i_node );
1165 QApplication::postEvent( mim, event );
1168 static int PLItemRemoved
1169 ( vlc_object_t * obj, const char *var, vlc_value_t old, vlc_value_t cur, void *data )
1171 MainInputManager *mim = static_cast<MainInputManager*>(data);
1173 PLEvent *event = new PLEvent( PLItemRemoved_Type, cur.i_int, 0 );
1174 QApplication::postEvent( mim, event );
1178 static int RandomChanged
1179 ( vlc_object_t * obj, const char *var, vlc_value_t old, vlc_value_t cur, void *data )
1181 MainInputManager *mim = static_cast<MainInputManager*>(data);
1183 IMEvent *event = new IMEvent( RandomChanged_Type );
1184 QApplication::postEvent( mim, event );
1188 /* Probably could be merged with next callback */
1189 static int LoopChanged
1190 ( vlc_object_t * obj, const char *var, vlc_value_t old, vlc_value_t cur, void *data )
1192 MainInputManager *mim = static_cast<MainInputManager*>(data);
1194 IMEvent *event = new IMEvent( LoopChanged_Type );
1195 QApplication::postEvent( mim, event );
1199 static int RepeatChanged
1200 ( vlc_object_t * obj, const char *var, vlc_value_t old, vlc_value_t cur, void *data )
1202 MainInputManager *mim = static_cast<MainInputManager*>(data);
1204 IMEvent *event = new IMEvent( RepeatChanged_Type );
1205 QApplication::postEvent( mim, event );