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 LeafToParent( vlc_object_t *, const char *,
41 vlc_value_t, vlc_value_t, void * );
42 static int PLItemChanged( vlc_object_t *, const char *,
43 vlc_value_t, vlc_value_t, void * );
44 static int PLItemAppended( vlc_object_t *, const char *,
45 vlc_value_t, vlc_value_t, void * );
46 static int PLItemRemoved( vlc_object_t *, const char *,
47 vlc_value_t, vlc_value_t, void * );
48 static int VolumeChanged( vlc_object_t *, const char *,
49 vlc_value_t, vlc_value_t, void * );
50 static int SoundMuteChanged( vlc_object_t *, const char *,
51 vlc_value_t, vlc_value_t, void * );
53 static int RandomChanged( vlc_object_t *, const char *,
54 vlc_value_t, vlc_value_t, void * );
55 static int LoopChanged( vlc_object_t *, const char *,
56 vlc_value_t, vlc_value_t, void * );
57 static int RepeatChanged( vlc_object_t *, const char *,
58 vlc_value_t, vlc_value_t, void * );
61 static int InputEvent( vlc_object_t *, const char *,
62 vlc_value_t, vlc_value_t, void * );
63 static int VbiEvent( vlc_object_t *, const char *,
64 vlc_value_t, vlc_value_t, void * );
67 /**********************************************************************
68 * InputManager implementation
69 **********************************************************************
70 * The Input Manager can be the main one around the playlist
71 * But can also be used for VLM dialog or similar
72 **********************************************************************/
74 InputManager::InputManager( QObject *parent, intf_thread_t *_p_intf) :
75 QObject( parent ), p_intf( _p_intf )
77 i_old_playing_status = END_S;
87 f_cache = -1.; /* impossible initial value, different from all */
90 InputManager::~InputManager()
95 /* Define the Input used.
96 Add the callbacks on input
97 p_input is held once here */
98 void InputManager::setInput( input_thread_t *_p_input )
102 if( p_input && !( p_input->b_dead || !vlc_object_alive (p_input) ) )
104 msg_Dbg( p_intf, "IM: Setting an input" );
105 vlc_object_hold( p_input );
114 p_item = input_GetItem( p_input );
115 emit rateChanged( var_GetFloat( p_input, "rate" ) );
121 assert( !p_input_vbi );
122 emit rateChanged( var_InheritFloat( p_intf, "rate" ) );
126 /* delete Input if it ever existed.
127 Delete the callbacls on input
128 p_input is released once here */
129 void InputManager::delInput()
131 if( !p_input ) return;
132 msg_Dbg( p_intf, "IM: Deleting the input" );
135 i_old_playing_status = END_S;
145 vlc_object_release( p_input_vbi );
149 vlc_object_release( p_input );
152 emit positionUpdated( -1.0, 0 ,0 );
153 emit rateChanged( var_InheritFloat( p_intf, "rate" ) );
154 emit nameChanged( "" );
155 emit chapterChanged( 0 );
156 emit titleChanged( 0 );
157 emit statusChanged( END_S );
159 emit teletextPossible( false );
160 emit AtoBchanged( false, false );
161 emit voutChanged( false );
162 emit voutListChanged( NULL, 0 );
164 /* Reset all InfoPanels but stats */
165 emit artChanged( NULL );
166 emit infoChanged( NULL );
167 emit currentMetaChanged( (input_item_t *)NULL );
169 emit encryptionChanged( false );
170 emit recordingStateChanged( false );
172 emit cachingChanged( 1 );
175 /* Convert the event from the callbacks in actions */
176 void InputManager::customEvent( QEvent *event )
178 int i_type = event->type();
179 IMEvent *ple = static_cast<IMEvent *>(event);
181 if( i_type == ItemChanged_Type )
182 UpdateMeta( ple->p_item );
190 case PositionUpdate_Type:
193 case StatisticsUpdate_Type:
196 case ItemChanged_Type:
197 /* Ignore ItemChanged_Type event that does not apply to our input */
198 if( p_item == ple->p_item )
203 /* Update duration of file */
206 case ItemStateChanged_Type:
207 // TODO: Fusion with above state
210 // UpdateNavigation(); This shouldn't be useful now
211 // UpdateTeletext(); Same
213 case NameChanged_Type:
216 case MetaChanged_Type:
218 UpdateName(); /* Needed for NowPlaying */
219 UpdateArt(); /* Art is part of meta in the core */
221 case InfoChanged_Type:
224 case ItemTitleChanged_Type:
226 UpdateName(); /* Display the name of the Chapter, if exists */
228 case ItemRateChanged_Type:
231 case ItemEsChanged_Type:
233 // We don't do anything ES related. Why ?
235 case ItemTeletextChanged_Type:
238 case InterfaceVoutUpdate_Type:
241 case SynchroChanged_Type:
242 emit synchroChanged();
244 case CachingEvent_Type:
247 case BookmarksChanged_Type:
248 emit bookmarksChanged();
250 case InterfaceAoutUpdate_Type:
253 case RecordingEvent_Type:
256 case ProgramChanged_Type:
257 UpdateProgramEvent();
260 msg_Warn( p_intf, "This shouldn't happen: %i", i_type );
265 /* Add the callbacks on Input. Self explanatory */
266 inline void InputManager::addCallbacks()
268 var_AddCallback( p_input, "intf-event", InputEvent, this );
271 /* Delete the callbacks on Input. Self explanatory */
272 inline void InputManager::delCallbacks()
274 var_DelCallback( p_input, "intf-event", InputEvent, this );
277 /* Static callbacks for IM */
278 static int ItemChanged( vlc_object_t *p_this, const char *psz_var,
279 vlc_value_t oldval, vlc_value_t newval, void *param )
281 InputManager *im = (InputManager*)param;
282 input_item_t *p_item = static_cast<input_item_t *>(newval.p_address);
284 IMEvent *event = new IMEvent( ItemChanged_Type, p_item );
285 QApplication::postEvent( im, event );
289 static int InputEvent( vlc_object_t *p_this, const char *,
290 vlc_value_t, vlc_value_t newval, void *param )
292 InputManager *im = (InputManager*)param;
295 switch( newval.i_int )
297 case INPUT_EVENT_STATE:
298 event = new IMEvent( ItemStateChanged_Type );
300 case INPUT_EVENT_RATE:
301 event = new IMEvent( ItemRateChanged_Type );
303 case INPUT_EVENT_POSITION:
304 //case INPUT_EVENT_LENGTH:
305 event = new IMEvent( PositionUpdate_Type );
308 case INPUT_EVENT_TITLE:
309 case INPUT_EVENT_CHAPTER:
310 event = new IMEvent( ItemTitleChanged_Type );
314 event = new IMEvent( ItemEsChanged_Type );
316 case INPUT_EVENT_TELETEXT:
317 event = new IMEvent( ItemTeletextChanged_Type );
320 case INPUT_EVENT_STATISTICS:
321 event = new IMEvent( StatisticsUpdate_Type );
324 case INPUT_EVENT_VOUT:
325 event = new IMEvent( InterfaceVoutUpdate_Type );
327 case INPUT_EVENT_AOUT:
328 event = new IMEvent( InterfaceAoutUpdate_Type );
331 case INPUT_EVENT_ITEM_META: /* Codec MetaData + Art */
332 event = new IMEvent( MetaChanged_Type );
334 case INPUT_EVENT_ITEM_INFO: /* Codec Info */
335 event = new IMEvent( InfoChanged_Type );
337 case INPUT_EVENT_ITEM_NAME:
338 event = new IMEvent( NameChanged_Type );
341 case INPUT_EVENT_AUDIO_DELAY:
342 case INPUT_EVENT_SUBTITLE_DELAY:
343 event = new IMEvent( SynchroChanged_Type );
346 case INPUT_EVENT_CACHE:
347 event = new IMEvent( CachingEvent_Type );
350 case INPUT_EVENT_BOOKMARK:
351 event = new IMEvent( BookmarksChanged_Type );
354 case INPUT_EVENT_RECORD:
355 event = new IMEvent( RecordingEvent_Type );
358 case INPUT_EVENT_PROGRAM:
359 /* This is for PID changes */
360 event = new IMEvent( ProgramChanged_Type );
363 case INPUT_EVENT_SIGNAL:
364 /* This is for capture-card signals */
365 /* event = new IMEvent( SignalChanged_Type );
373 QApplication::postEvent( im, event );
377 static int VbiEvent( vlc_object_t *, const char *,
378 vlc_value_t, vlc_value_t, void *param )
380 InputManager *im = (InputManager*)param;
381 IMEvent *event = new IMEvent( ItemTeletextChanged_Type );
383 QApplication::postEvent( im, event );
387 void InputManager::UpdatePosition()
389 /* Update position */
393 i_length = var_GetTime( p_input , "length" ) / 1000000;
394 i_time = var_GetTime( p_input , "time");
395 f_pos = var_GetFloat( p_input , "position" );
396 emit positionUpdated( f_pos, i_time, i_length );
399 void InputManager::UpdateNavigation()
401 /* Update navigation status */
402 vlc_value_t val; val.i_int = 0;
403 vlc_value_t val2; val2.i_int = 0;
406 var_Change( p_input, "title", VLC_VAR_CHOICESCOUNT, &val, NULL );
410 emit titleChanged( true );
411 msg_Dbg( p_intf, "Title %i", val.i_int );
412 /* p_input != NULL since val.i_int != 0 */
413 var_Change( p_input, "chapter", VLC_VAR_CHOICESCOUNT, &val2, NULL );
414 emit chapterChanged( (val2.i_int > 1) || ( val2.i_int > 0 && val.i_int > 1 ) );
415 msg_Dbg( p_intf, "Chapter: %i", val2.i_int );
418 emit titleChanged( false );
421 void InputManager::UpdateStatus()
423 /* Update playing status */
424 int state = var_GetInteger( p_input, "state" );
425 if( i_old_playing_status != state )
427 i_old_playing_status = state;
428 emit statusChanged( state );
432 void InputManager::UpdateRate()
435 float f_new_rate = var_GetFloat( p_input, "rate" );
436 if( f_new_rate != f_rate )
440 emit rateChanged( f_rate );
444 void InputManager::UpdateName()
446 /* Update text, name and nowplaying */
449 /* Try to get the Title, then the Name */
450 char *psz_name = input_item_GetTitleFbName( input_GetItem( p_input ) );
452 /* Try to get the nowplaying */
453 char *psz_nowplaying =
454 input_item_GetNowPlaying( input_GetItem( p_input ) );
455 if( !EMPTY_STR( psz_nowplaying ) )
457 text.sprintf( "%s - %s", psz_nowplaying, psz_name );
459 else /* Do it ourself */
461 char *psz_artist = input_item_GetArtist( input_GetItem( p_input ) );
463 if( !EMPTY_STR( psz_artist ) )
464 text.sprintf( "%s - %s", psz_artist, psz_name );
466 text.sprintf( "%s", psz_name );
470 /* Free everything */
472 free( psz_nowplaying );
474 /* If we have Nothing */
477 psz_name = input_item_GetURI( input_GetItem( p_input ) );
478 text.sprintf( "%s", psz_name );
479 text = text.remove( 0, text.lastIndexOf( DIR_SEP ) + 1 );
483 if( oldName != text )
485 emit nameChanged( text );
490 bool InputManager::hasAudio()
495 var_Change( p_input, "audio-es", VLC_VAR_CHOICESCOUNT, &val, NULL );
496 return val.i_int > 0;
501 void InputManager::UpdateTeletext()
505 const bool b_enabled = var_CountChoices( p_input, "teletext-es" ) > 0;
506 const int i_teletext_es = var_GetInteger( p_input, "teletext-es" );
508 /* Teletext is possible. Show the buttons */
509 emit teletextPossible( b_enabled );
511 /* If Teletext is selected */
512 if( b_enabled && i_teletext_es >= 0 )
514 /* Then, find the current page */
516 bool b_transparent = false;
520 var_DelCallback( p_input_vbi, "vbi-page", VbiEvent, this );
521 vlc_object_release( p_input_vbi );
524 if( input_GetEsObjects( p_input, i_teletext_es, &p_input_vbi, NULL, NULL ) )
529 /* This callback is not remove explicitly, but interfaces
530 * are guaranted to outlive input */
531 var_AddCallback( p_input_vbi, "vbi-page", VbiEvent, this );
533 i_page = var_GetInteger( p_input_vbi, "vbi-page" );
534 b_transparent = !var_GetBool( p_input_vbi, "vbi-opaque" );
536 emit newTelexPageSet( i_page );
537 emit teletextTransparencyActivated( b_transparent );
540 emit teletextActivated( b_enabled && i_teletext_es >= 0 );
544 emit teletextActivated( false );
545 emit teletextPossible( false );
549 void InputManager::UpdateVout()
553 /* Get current vout lists from input */
555 vout_thread_t **pp_vout;
556 if( input_Control( p_input, INPUT_GET_VOUTS, &pp_vout, &i_vout ) )
563 emit voutListChanged( pp_vout, i_vout );
566 bool b_old_video = b_video;
567 b_video = i_vout > 0;
568 if( !!b_old_video != !!b_video )
569 emit voutChanged( b_video );
571 /* Release the vout list */
572 for( int i = 0; i < i_vout; i++ )
573 vlc_object_release( (vlc_object_t*)pp_vout[i] );
577 void InputManager::UpdateAout()
584 void InputManager::UpdateCaching()
586 if(!hasInput()) return;
588 float f_newCache = var_GetFloat ( p_input, "cache" );
589 if( f_newCache != f_cache )
591 f_cache = f_newCache;
593 emit cachingChanged( f_cache );
597 void InputManager::requestArtUpdate()
601 playlist_AskForArtEnqueue( pl_Get(p_intf), input_GetItem( p_input ) );
605 /* No input will signal the cover art to update,
606 * let's do it ourself */
611 const QString InputManager::decodeArtURL( input_item_t *p_item )
615 char *psz_art = input_item_GetArtURL( p_item );
618 char *psz = make_path( psz_art );
624 /* Taglib seems to define a attachment://, It won't work yet */
625 url = url.replace( "attachment://", "" );
627 return qfu( psz_art ? psz_art : "" );
630 void InputManager::UpdateArt()
635 url = decodeArtURL( input_GetItem( p_input ) );
637 /* the art hasn't changed, no need to update */
641 /* Update Art meta */
643 emit artChanged( artUrl );
646 inline void InputManager::UpdateStats()
648 emit statisticsUpdated( input_GetItem( p_input ) );
651 inline void InputManager::UpdateMeta( input_item_t *p_item )
653 emit metaChanged( p_item );
656 inline void InputManager::UpdateMeta()
658 emit currentMetaChanged( input_GetItem( p_input ) );
661 inline void InputManager::UpdateInfo()
663 emit infoChanged( input_GetItem( p_input ) );
666 void InputManager::UpdateRecord()
670 emit recordingStateChanged( var_GetBool( p_input, "record" ) );
674 void InputManager::UpdateProgramEvent()
678 bool b_scrambled = var_GetBool( p_input, "program-scrambled" );
679 emit encryptionChanged( b_scrambled );
683 /* User update of the slider */
684 void InputManager::sliderUpdate( float new_pos )
687 var_SetFloat( p_input, "position", new_pos );
688 emit seekRequested( new_pos );
691 /* User togglePlayPause */
692 void InputManager::togglePlayPause()
696 int state = var_GetInteger( p_input, "state" );
697 state = ( state != PLAYING_S ) ? PLAYING_S : PAUSE_S;
698 var_SetInteger( p_input, "state", state );
702 void InputManager::sectionPrev()
706 int i_type = var_Type( p_input, "next-chapter" );
707 var_TriggerCallback( p_input, (i_type & VLC_VAR_TYPE) != 0 ?
708 "prev-chapter":"prev-title" );
712 void InputManager::sectionNext()
716 int i_type = var_Type( p_input, "next-chapter" );
717 var_TriggerCallback( p_input, (i_type & VLC_VAR_TYPE) != 0 ?
718 "next-chapter":"next-title" );
722 void InputManager::sectionMenu()
726 vlc_value_t val, text;
728 if( var_Change( p_input, "title 0", VLC_VAR_GETLIST, &val, &text ) < 0 )
731 /* XXX is it "Root" or "Title" we want here ?" (set 0 by default) */
733 for( int i = 0; i < val.p_list->i_count; i++ )
735 if( !strcmp( text.p_list->p_values[i].psz_string, "Title" ) )
738 var_FreeList( &val, &text );
740 var_SetInteger( p_input, "title 0", root );
748 /* Set a new Teletext Page */
749 void InputManager::telexSetPage( int page )
751 if( hasInput() && p_input_vbi )
753 const int i_teletext_es = var_GetInteger( p_input, "teletext-es" );
755 if( i_teletext_es >= 0 )
757 var_SetInteger( p_input_vbi, "vbi-page", page );
758 emit newTelexPageSet( page );
763 /* Set the transparency on teletext */
764 void InputManager::telexSetTransparency( bool b_transparentTelextext )
766 if( hasInput() && p_input_vbi )
768 var_SetBool( p_input_vbi, "vbi-opaque", !b_transparentTelextext );
769 emit teletextTransparencyActivated( b_transparentTelextext );
773 void InputManager::activateTeletext( bool b_enable )
777 if( hasInput() && !var_Change( p_input, "teletext-es", VLC_VAR_GETLIST, &list, &text ) )
779 if( list.p_list->i_count > 0 )
781 /* Prefer the page 100 if it is present */
783 for( i = 0; i < text.p_list->i_count; i++ )
785 /* The description is the page number as a string */
786 const char *psz_page = text.p_list->p_values[i].psz_string;
787 if( psz_page && !strcmp( psz_page, "100" ) )
790 if( i >= list.p_list->i_count )
792 var_SetInteger( p_input, "spu-es", b_enable ? list.p_list->p_values[i].i_int : -1 );
794 var_FreeList( &list, &text );
798 void InputManager::reverse()
802 float f_rate = var_GetFloat( p_input, "rate" );
803 var_SetFloat( p_input, "rate", -f_rate );
807 void InputManager::slower()
810 var_TriggerCallback( p_input, "rate-slower" );
813 void InputManager::faster()
816 var_TriggerCallback( p_input, "rate-faster" );
819 void InputManager::littlefaster()
821 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_RATE_FASTER_FINE );
824 void InputManager::littleslower()
826 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_RATE_SLOWER_FINE );
829 void InputManager::normalRate()
832 var_SetFloat( p_input, "rate", 1. );
835 void InputManager::setRate( int new_rate )
838 var_SetFloat( p_input, "rate",
839 (float)INPUT_RATE_DEFAULT / (float)new_rate );
842 void InputManager::jumpFwd()
844 int i_interval = var_InheritInteger( p_input, "short-jump-size" );
847 mtime_t val = (mtime_t)(i_interval) * 1000000L;
848 var_SetTime( p_input, "time-offset", val );
852 void InputManager::jumpBwd()
854 int i_interval = var_InheritInteger( p_input, "short-jump-size" );
857 mtime_t val = -1 *(mtime_t)(i_interval) * 1000000L;
858 var_SetTime( p_input, "time-offset", val );
862 void InputManager::setAtoB()
866 timeA = var_GetTime( THEMIM->getInput(), "time" );
870 timeB = var_GetTime( THEMIM->getInput(), "time" );
871 var_SetTime( THEMIM->getInput(), "time" , timeA );
872 CONNECT( this, positionUpdated( float, int64_t, int ),
873 this, AtoBLoop( float, int64_t, int ) );
879 disconnect( this, SIGNAL( positionUpdated( float, int64_t, int ) ),
880 this, SLOT( AtoBLoop( float, int64_t, int ) ) );
882 emit AtoBchanged( (timeA != 0 ), (timeB != 0 ) );
885 /* Function called regularly when in an AtoB loop */
886 void InputManager::AtoBLoop( float, int64_t i_time, int )
890 if( i_time >= timeB || i_time < timeA )
891 var_SetTime( THEMIM->getInput(), "time" , timeA );
895 /**********************************************************************
896 * MainInputManager implementation. Wrap an input manager and
897 * take care of updating the main playlist input.
898 * Used in the main playlist Dialog
899 **********************************************************************/
900 MainInputManager * MainInputManager::instance = NULL;
902 MainInputManager::MainInputManager( intf_thread_t *_p_intf )
903 : QObject(NULL), p_intf( _p_intf )
906 im = new InputManager( this, p_intf );
908 var_AddCallback( THEPL, "item-change", ItemChanged, im );
909 var_AddCallback( THEPL, "item-current", PLItemChanged, this );
910 var_AddCallback( THEPL, "activity", PLItemChanged, this );
911 var_AddCallback( THEPL, "leaf-to-parent", LeafToParent, this );
912 var_AddCallback( THEPL, "playlist-item-append", PLItemAppended, this );
913 var_AddCallback( THEPL, "playlist-item-deleted", PLItemRemoved, this );
914 var_AddCallback( THEPL, "random", RandomChanged, this );
915 var_AddCallback( THEPL, "repeat", RepeatChanged, this );
916 var_AddCallback( THEPL, "loop", LoopChanged, this );
918 var_AddCallback( THEPL, "volume-change", VolumeChanged, this );
919 var_AddCallback( THEPL, "volume-muted", SoundMuteChanged, this );
921 /* Warn our embedded IM about input changes */
922 DCONNECT( this, inputChanged( input_thread_t * ),
923 im, setInput( input_thread_t * ) );
925 /* emit check if playlist has already started playing */
926 input_thread_t *p_input = playlist_CurrentInput( THEPL );
929 input_item_t *p_item = input_GetItem( p_input );
932 IMEvent *event = new IMEvent( ItemChanged_Type, p_item );
933 customEvent( event );
936 vlc_object_release( p_input );
940 MainInputManager::~MainInputManager()
944 emit inputChanged( NULL );
945 var_DelCallback( p_input, "state", PLItemChanged, this );
946 vlc_object_release( p_input );
949 var_DelCallback( THEPL, "volume-change", VolumeChanged, this );
950 var_DelCallback( THEPL, "volume-muted", SoundMuteChanged, this );
952 var_DelCallback( THEPL, "activity", PLItemChanged, this );
953 var_DelCallback( THEPL, "item-change", ItemChanged, im );
954 var_DelCallback( THEPL, "leaf-to-parent", LeafToParent, this );
956 var_DelCallback( THEPL, "item-current", PLItemChanged, this );
957 var_DelCallback( THEPL, "playlist-item-append", PLItemAppended, this );
958 var_DelCallback( THEPL, "playlist-item-deleted", PLItemRemoved, this );
959 var_DelCallback( THEPL, "random", RandomChanged, this );
960 var_DelCallback( THEPL, "repeat", RepeatChanged, this );
961 var_DelCallback( THEPL, "loop", LoopChanged, this );
965 vout_thread_t* MainInputManager::getVout()
967 return p_input ? input_GetVout( p_input ) : NULL;
970 aout_instance_t * MainInputManager::getAout()
972 return p_input ? input_GetAout( p_input ) : NULL;
975 void MainInputManager::customEvent( QEvent *event )
977 int type = event->type();
982 // msg_Dbg( p_intf, "New MainIM Event of type: %i", type );
985 case VolumeChanged_Type:
986 emit volumeChanged();
988 case SoundMuteChanged_Type:
989 emit soundMuteChanged();
991 case PLItemAppended_Type:
992 plEv = static_cast<PLEvent*>( event );
993 emit playlistItemAppended( plEv->i_item, plEv->i_parent );
995 case PLItemRemoved_Type:
996 plEv = static_cast<PLEvent*>( event );
997 emit playlistItemRemoved( plEv->i_item );
999 case RandomChanged_Type:
1000 emit randomChanged( var_GetBool( THEPL, "random" ) );
1002 case LoopChanged_Type:
1003 case RepeatChanged_Type:
1006 case LeafToParent_Type:
1007 imEv = static_cast<IMEvent*>( event );
1008 emit leafBecameParent( imEv->p_item );
1010 if( type != ItemChanged_Type ) return;
1013 /* Should be PLItemChanged Event */
1014 if( !p_intf->p_sys->b_isDialogProvider )
1016 if( p_input && ( p_input->b_dead || !vlc_object_alive (p_input) ) )
1018 emit inputChanged( p_input );
1019 var_DelCallback( p_input, "state", PLItemChanged, this );
1020 vlc_object_release( p_input );
1027 p_input = playlist_CurrentInput(THEPL);
1030 var_AddCallback( p_input, "state", PLItemChanged, this );
1031 emit inputChanged( p_input );
1037 /* remove previous stored p_input */
1040 vlc_object_release( p_input );
1043 /* we are working as a dialogs provider */
1044 p_input = playlist_CurrentInput( pl_Get(p_intf) );
1047 emit inputChanged( p_input );
1052 /* Playlist Control functions */
1053 void MainInputManager::stop()
1055 playlist_Stop( THEPL );
1058 void MainInputManager::next()
1060 playlist_Next( THEPL );
1063 void MainInputManager::prev()
1065 playlist_Prev( THEPL );
1068 void MainInputManager::togglePlayPause()
1070 /* No input, play */
1072 playlist_Play( THEPL );
1074 getIM()->togglePlayPause();
1077 void MainInputManager::play()
1079 /* No input, play */
1081 playlist_Play( THEPL );
1084 if( PLAYING_S != var_GetInteger( p_input, "state" ) )
1086 getIM()->togglePlayPause();
1091 void MainInputManager::pause()
1093 if(p_input && PLAYING_S == var_GetInteger( p_input, "state" ) )
1095 getIM()->togglePlayPause();
1099 void MainInputManager::toggleRandom()
1101 var_ToggleBool( THEPL, "random" );
1104 void MainInputManager::notifyRepeatLoop()
1106 int i_value = var_GetBool( THEPL, "loop" ) * REPEAT_ALL
1107 + var_GetBool( THEPL, "repeat" ) * REPEAT_ONE;
1109 emit repeatLoopChanged( i_value );
1112 void MainInputManager::loopRepeatLoopStatus()
1114 /* Toggle Normal -> Loop -> Repeat -> Normal ... */
1115 if( var_GetBool( THEPL, "repeat" ) )
1116 var_SetBool( THEPL, "repeat", false );
1117 else if( var_GetBool( THEPL, "loop" ) )
1119 var_SetBool( THEPL, "loop", false );
1120 var_SetBool( THEPL, "repeat", true );
1123 var_SetBool( THEPL, "loop", true );
1126 void MainInputManager::activatePlayQuit( bool b_exit )
1128 var_SetBool( THEPL, "play-and-exit", b_exit );
1132 /****************************
1133 * Static callbacks for MIM *
1134 ****************************/
1135 static int PLItemChanged( vlc_object_t *p_this, const char *psz_var,
1136 vlc_value_t oldval, vlc_value_t, void *param )
1138 MainInputManager *mim = (MainInputManager*)param;
1140 IMEvent *event = new IMEvent( ItemChanged_Type );
1141 QApplication::postEvent( mim, event );
1145 static int LeafToParent( vlc_object_t *p_this, const char *psz_var,
1146 vlc_value_t oldval, vlc_value_t newval, void *param )
1148 MainInputManager *mim = (MainInputManager*)param;
1150 IMEvent *event = new IMEvent( LeafToParent_Type,
1151 static_cast<input_item_t*>( newval.p_address ) );
1152 QApplication::postEvent( mim, event );
1156 static int VolumeChanged( vlc_object_t *p_this, const char *psz_var,
1157 vlc_value_t oldval, vlc_value_t newval, void *param )
1159 MainInputManager *mim = (MainInputManager*)param;
1161 IMEvent *event = new IMEvent( VolumeChanged_Type );
1162 QApplication::postEvent( mim, event );
1166 static int SoundMuteChanged( vlc_object_t *p_this, const char *psz_var,
1167 vlc_value_t oldval, vlc_value_t newval, void *param )
1169 MainInputManager *mim = (MainInputManager*)param;
1171 IMEvent *event = new IMEvent( SoundMuteChanged_Type );
1172 QApplication::postEvent( mim, event );
1176 static int PLItemAppended
1177 ( vlc_object_t * obj, const char *var, vlc_value_t old, vlc_value_t cur, void *data )
1179 MainInputManager *mim = static_cast<MainInputManager*>(data);
1180 playlist_add_t *p_add = static_cast<playlist_add_t*>( cur.p_address );
1182 PLEvent *event = new PLEvent( PLItemAppended_Type, p_add->i_item, p_add->i_node );
1183 QApplication::postEvent( mim, event );
1186 static int PLItemRemoved
1187 ( vlc_object_t * obj, const char *var, vlc_value_t old, vlc_value_t cur, void *data )
1189 MainInputManager *mim = static_cast<MainInputManager*>(data);
1191 PLEvent *event = new PLEvent( PLItemRemoved_Type, cur.i_int, 0 );
1192 QApplication::postEvent( mim, event );
1196 static int RandomChanged
1197 ( vlc_object_t * obj, const char *var, vlc_value_t old, vlc_value_t cur, void *data )
1199 MainInputManager *mim = static_cast<MainInputManager*>(data);
1201 IMEvent *event = new IMEvent( RandomChanged_Type );
1202 QApplication::postEvent( mim, event );
1206 /* Probably could be merged with next callback */
1207 static int LoopChanged
1208 ( vlc_object_t * obj, const char *var, vlc_value_t old, vlc_value_t cur, void *data )
1210 MainInputManager *mim = static_cast<MainInputManager*>(data);
1212 IMEvent *event = new IMEvent( LoopChanged_Type );
1213 QApplication::postEvent( mim, event );
1217 static int RepeatChanged
1218 ( vlc_object_t * obj, const char *var, vlc_value_t old, vlc_value_t cur, void *data )
1220 MainInputManager *mim = static_cast<MainInputManager*>(data);
1222 IMEvent *event = new IMEvent( RepeatChanged_Type );
1223 QApplication::postEvent( mim, event );