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;
84 f_cache = -1.; /* impossible initial value, different from all */
87 InputManager::~InputManager()
92 /* Define the Input used.
93 Add the callbacks on input
94 p_input is held once here */
95 void InputManager::setInput( input_thread_t *_p_input )
99 if( p_input && !( p_input->b_dead || !vlc_object_alive (p_input) ) )
101 msg_Dbg( p_intf, "IM: Setting an input" );
102 vlc_object_hold( p_input );
103 emit statusChanged( PLAYING_S );
110 p_item = input_GetItem( p_input );
116 emit rateChanged( INPUT_RATE_DEFAULT );
120 /* delete Input if it ever existed.
121 Delete the callbacls on input
122 p_input is released once here */
123 void InputManager::delInput()
125 if( !p_input ) return;
126 msg_Dbg( p_intf, "IM: Deleting the input" );
129 i_old_playing_status = END_S;
137 vlc_object_release( p_input );
140 emit positionUpdated( -1.0, 0 ,0 );
141 emit rateChanged( INPUT_RATE_DEFAULT ); /* TODO: Do we want this ? */
142 emit nameChanged( "" );
143 emit chapterChanged( 0 );
144 emit titleChanged( 0 );
145 emit statusChanged( END_S );
147 emit teletextPossible( false );
148 emit AtoBchanged( false, false );
149 emit voutChanged( false );
150 emit voutListChanged( NULL, 0 );
152 /* Reset all InfoPanels but stats */
153 emit artChanged( NULL );
154 emit infoChanged( NULL );
155 emit currentMetaChanged( (input_item_t *)NULL );
157 emit encryptionChanged( false );
158 emit recordingStateChanged( false );
161 /* Convert the event from the callbacks in actions */
162 void InputManager::customEvent( QEvent *event )
164 int i_type = event->type();
165 IMEvent *ple = static_cast<IMEvent *>(event);
167 if( i_type == ItemChanged_Type )
168 UpdateMeta( ple->p_item );
176 case PositionUpdate_Type:
179 case StatisticsUpdate_Type:
182 case ItemChanged_Type:
183 /* Ignore ItemChanged_Type event that does not apply to our input */
184 if( p_item == ple->p_item )
189 /* Update duration of file */
192 case ItemStateChanged_Type:
193 // TODO: Fusion with above state
196 // UpdateNavigation(); This shouldn't be useful now
197 // UpdateTeletext(); Same
199 case NameChanged_Type:
202 case MetaChanged_Type:
204 UpdateName(); /* Needed for NowPlaying */
205 UpdateArt(); /* Art is part of meta in the core */
207 case InfoChanged_Type:
210 case ItemTitleChanged_Type:
212 UpdateName(); /* Display the name of the Chapter, if exists */
214 case ItemRateChanged_Type:
217 case ItemEsChanged_Type:
219 // We don't do anything ES related. Why ?
221 case ItemTeletextChanged_Type:
224 case InterfaceVoutUpdate_Type:
227 case SynchroChanged_Type:
228 emit synchroChanged();
230 case CachingEvent_Type:
233 case BookmarksChanged_Type:
234 emit bookmarksChanged();
236 case InterfaceAoutUpdate_Type:
239 case RecordingEvent_Type:
242 case ProgramChanged_Type:
243 UpdateProgramEvent();
246 msg_Warn( p_intf, "This shouldn't happen: %i", i_type );
251 /* Add the callbacks on Input. Self explanatory */
252 inline void InputManager::addCallbacks()
254 var_AddCallback( p_input, "intf-event", InputEvent, this );
257 /* Delete the callbacks on Input. Self explanatory */
258 inline void InputManager::delCallbacks()
260 var_DelCallback( p_input, "intf-event", InputEvent, this );
263 /* Static callbacks for IM */
264 static int ItemChanged( vlc_object_t *p_this, const char *psz_var,
265 vlc_value_t oldval, vlc_value_t newval, void *param )
267 InputManager *im = (InputManager*)param;
268 input_item_t *p_item = static_cast<input_item_t *>(newval.p_address);
270 IMEvent *event = new IMEvent( ItemChanged_Type, p_item );
271 QApplication::postEvent( im, event );
275 static int InputEvent( vlc_object_t *p_this, const char *,
276 vlc_value_t, vlc_value_t newval, void *param )
278 InputManager *im = (InputManager*)param;
281 switch( newval.i_int )
283 case INPUT_EVENT_STATE:
284 event = new IMEvent( ItemStateChanged_Type );
286 case INPUT_EVENT_RATE:
287 event = new IMEvent( ItemRateChanged_Type );
289 case INPUT_EVENT_POSITION:
290 //case INPUT_EVENT_LENGTH:
291 event = new IMEvent( PositionUpdate_Type );
294 case INPUT_EVENT_TITLE:
295 case INPUT_EVENT_CHAPTER:
296 event = new IMEvent( ItemTitleChanged_Type );
300 event = new IMEvent( ItemEsChanged_Type );
302 case INPUT_EVENT_TELETEXT:
303 event = new IMEvent( ItemTeletextChanged_Type );
306 case INPUT_EVENT_STATISTICS:
307 event = new IMEvent( StatisticsUpdate_Type );
310 case INPUT_EVENT_VOUT:
311 event = new IMEvent( InterfaceVoutUpdate_Type );
313 case INPUT_EVENT_AOUT:
314 event = new IMEvent( InterfaceAoutUpdate_Type );
317 case INPUT_EVENT_ITEM_META: /* Codec MetaData + Art */
318 event = new IMEvent( MetaChanged_Type );
320 case INPUT_EVENT_ITEM_INFO: /* Codec Info */
321 event = new IMEvent( InfoChanged_Type );
323 case INPUT_EVENT_ITEM_NAME:
324 event = new IMEvent( NameChanged_Type );
327 case INPUT_EVENT_AUDIO_DELAY:
328 case INPUT_EVENT_SUBTITLE_DELAY:
329 event = new IMEvent( SynchroChanged_Type );
332 case INPUT_EVENT_CACHE:
333 event = new IMEvent( CachingEvent_Type );
336 case INPUT_EVENT_BOOKMARK:
337 event = new IMEvent( BookmarksChanged_Type );
340 case INPUT_EVENT_RECORD:
341 event = new IMEvent( RecordingEvent_Type );
344 case INPUT_EVENT_PROGRAM:
345 /* This is for PID changes */
346 event = new IMEvent( ProgramChanged_Type );
349 case INPUT_EVENT_SIGNAL:
350 /* This is for capture-card signals */
351 /* event = new IMEvent( SignalChanged_Type );
359 QApplication::postEvent( im, event );
363 static int VbiEvent( vlc_object_t *, const char *,
364 vlc_value_t, vlc_value_t, void *param )
366 InputManager *im = (InputManager*)param;
367 IMEvent *event = new IMEvent( ItemTeletextChanged_Type );
369 QApplication::postEvent( im, event );
373 void InputManager::UpdatePosition()
375 /* Update position */
376 int i_length, i_time; /* Int is enough, since we store seconds */
378 i_length = var_GetTime( p_input , "length" ) / 1000000;
379 i_time = var_GetTime( p_input , "time") / 1000000;
380 f_pos = var_GetFloat( p_input , "position" );
381 emit positionUpdated( f_pos, i_time, i_length );
384 void InputManager::UpdateNavigation()
386 /* Update navigation status */
387 vlc_value_t val; val.i_int = 0;
390 var_Change( p_input, "title", VLC_VAR_CHOICESCOUNT, &val, NULL );
394 emit titleChanged( true );
395 msg_Dbg( p_intf, "Title %i", val.i_int );
396 /* p_input != NULL since val.i_int != 0 */
398 var_Change( p_input, "chapter", VLC_VAR_CHOICESCOUNT, &val, NULL );
399 emit chapterChanged( (val.i_int > 0) );
400 msg_Dbg( p_intf, "Chapter: %i", val.i_int );
403 emit titleChanged( false );
406 void InputManager::UpdateStatus()
408 /* Update playing status */
409 int state = var_GetInteger( p_input, "state" );
410 if( i_old_playing_status != state )
412 i_old_playing_status = state;
413 emit statusChanged( state );
417 void InputManager::UpdateRate()
420 int i_new_rate = INPUT_RATE_DEFAULT / var_GetFloat( p_input, "rate" );
421 if( i_new_rate != i_rate )
425 emit rateChanged( i_rate );
429 void InputManager::UpdateName()
431 /* Update text, name and nowplaying */
434 /* Try to get the Title, then the Name */
435 char *psz_name = input_item_GetTitleFbName( input_GetItem( p_input ) );
437 /* Try to get the nowplaying */
438 char *psz_nowplaying =
439 input_item_GetNowPlaying( input_GetItem( p_input ) );
440 if( !EMPTY_STR( psz_nowplaying ) )
442 text.sprintf( "%s - %s", psz_nowplaying, psz_name );
444 else /* Do it ourself */
446 char *psz_artist = input_item_GetArtist( input_GetItem( p_input ) );
448 if( !EMPTY_STR( psz_artist ) )
449 text.sprintf( "%s - %s", psz_artist, psz_name );
451 text.sprintf( "%s", psz_name );
455 /* Free everything */
457 free( psz_nowplaying );
459 /* If we have Nothing */
462 psz_name = input_item_GetURI( input_GetItem( p_input ) );
463 text.sprintf( "%s", psz_name );
464 text = text.remove( 0, text.lastIndexOf( DIR_SEP ) + 1 );
468 if( oldName != text )
470 emit nameChanged( text );
475 bool InputManager::hasAudio()
480 var_Change( p_input, "audio-es", VLC_VAR_CHOICESCOUNT, &val, NULL );
481 return val.i_int > 0;
486 void InputManager::UpdateTeletext()
490 const bool b_enabled = var_CountChoices( p_input, "teletext-es" ) > 0;
491 const int i_teletext_es = var_GetInteger( p_input, "teletext-es" );
493 /* Teletext is possible. Show the buttons */
494 emit teletextPossible( b_enabled );
496 /* If Teletext is selected */
497 if( b_enabled && i_teletext_es >= 0 )
499 /* Then, find the current page */
501 bool b_transparent = false;
503 vlc_object_t *p_vbi = (vlc_object_t *)
504 vlc_object_find_name( p_input, "zvbi", FIND_CHILD );
508 /* We deleted it (if not here, it does not harm), because
509 * var_AddCallback will silently add a duplicated one */
510 var_DelCallback( p_vbi, "vbi-page", VbiEvent, this );
511 /* This callback is not remove explicitly, but interfaces
512 * are guaranted to outlive input */
513 var_AddCallback( p_vbi, "vbi-page", VbiEvent, this );
515 i_page = var_GetInteger( p_vbi, "vbi-page" );
516 b_transparent = !var_GetBool( p_vbi, "vbi-opaque" );
517 vlc_object_release( p_vbi );
519 emit newTelexPageSet( i_page );
520 emit teletextTransparencyActivated( b_transparent );
523 emit teletextActivated( b_enabled && i_teletext_es >= 0 );
527 emit teletextActivated( false );
528 emit teletextPossible( false );
532 void InputManager::UpdateVout()
536 /* Get current vout lists from input */
538 vout_thread_t **pp_vout;
539 if( input_Control( p_input, INPUT_GET_VOUTS, &pp_vout, &i_vout ) )
546 emit voutListChanged( pp_vout, i_vout );
549 bool b_old_video = b_video;
550 b_video = i_vout > 0;
551 if( !!b_old_video != !!b_video )
552 emit voutChanged( b_video );
554 /* Release the vout list */
555 for( int i = 0; i < i_vout; i++ )
556 vlc_object_release( (vlc_object_t*)pp_vout[i] );
560 void InputManager::UpdateAout()
567 void InputManager::UpdateCaching()
569 if(!hasInput()) return;
571 float f_newCache = var_GetFloat ( p_input, "cache" );
572 if( f_newCache != f_cache )
574 f_cache = f_newCache;
576 emit cachingChanged( f_cache );
580 void InputManager::requestArtUpdate()
584 playlist_t *p_playlist = pl_Hold( p_intf );
585 playlist_AskForArtEnqueue( p_playlist, input_GetItem( p_input ), pl_Unlocked );
586 pl_Release( p_intf );
590 /* No input will signal the cover art to update,
591 * let's do it ourself */
596 void InputManager::UpdateArt()
602 char *psz_art = input_item_GetArtURL( input_GetItem( p_input ) );
603 if( psz_art && !strncmp( psz_art, "file://", 7 ) &&
604 decode_URI( psz_art + 7 ) )
606 url = qfu( psz_art + 8 ); // Remove extra / starting on Win32.
608 url = qfu( psz_art + 7 );
612 url = url.replace( "file://", "" );
613 /* Taglib seems to define a attachment://, It won't work yet */
614 url = url.replace( "attachment://", "" );
617 /* Update Art meta */
618 emit artChanged( url );
621 inline void InputManager::UpdateStats()
623 emit statisticsUpdated( input_GetItem( p_input ) );
626 inline void InputManager::UpdateMeta( input_item_t *p_item )
628 emit metaChanged( p_item );
631 inline void InputManager::UpdateMeta()
633 emit currentMetaChanged( input_GetItem( p_input ) );
636 inline void InputManager::UpdateInfo()
638 emit infoChanged( input_GetItem( p_input ) );
641 void InputManager::UpdateRecord()
645 emit recordingStateChanged( var_GetBool( p_input, "record" ) );
649 void InputManager::UpdateProgramEvent()
653 bool b_scrambled = var_GetBool( p_input, "program-scrambled" );
654 emit encryptionChanged( b_scrambled );
658 /* User update of the slider */
659 void InputManager::sliderUpdate( float new_pos )
662 var_SetFloat( p_input, "position", new_pos );
665 /* User togglePlayPause */
666 void InputManager::togglePlayPause()
670 int state = var_GetInteger( p_input, "state" );
671 state = ( state != PLAYING_S ) ? PLAYING_S : PAUSE_S;
672 var_SetInteger( p_input, "state", state );
673 emit statusChanged( state );
677 void InputManager::sectionPrev()
681 int i_type = var_Type( p_input, "next-chapter" );
682 var_TriggerCallback( p_input, (i_type & VLC_VAR_TYPE) != 0 ?
683 "prev-chapter":"prev-title" );
687 void InputManager::sectionNext()
691 int i_type = var_Type( p_input, "next-chapter" );
692 var_TriggerCallback( p_input, (i_type & VLC_VAR_TYPE) != 0 ?
693 "next-chapter":"next-title" );
697 void InputManager::sectionMenu()
701 vlc_value_t val, text;
703 if( var_Change( p_input, "title 0", VLC_VAR_GETLIST, &val, &text ) < 0 )
706 /* XXX is it "Root" or "Title" we want here ?" (set 0 by default) */
708 for( int i = 0; i < val.p_list->i_count; i++ )
710 if( !strcmp( text.p_list->p_values[i].psz_string, "Title" ) )
713 var_FreeList( &val, &text );
715 var_SetInteger( p_input, "title 0", root );
723 /* Set a new Teletext Page */
724 void InputManager::telexSetPage( int page )
728 const int i_teletext_es = var_GetInteger( p_input, "teletext-es" );
730 if( i_teletext_es >= 0 )
732 vlc_object_t *p_vbi = (vlc_object_t *) vlc_object_find_name( p_input,
733 "zvbi", FIND_CHILD );
736 var_SetInteger( p_vbi, "vbi-page", page );
737 vlc_object_release( p_vbi );
738 emit newTelexPageSet( page );
744 /* Set the transparency on teletext */
745 void InputManager::telexSetTransparency( bool b_transparentTelextext )
749 vlc_object_t *p_vbi = (vlc_object_t *) vlc_object_find_name( p_input,
750 "zvbi", FIND_CHILD );
753 var_SetBool( p_vbi, "vbi-opaque", !b_transparentTelextext );
754 vlc_object_release( p_vbi );
755 emit teletextTransparencyActivated( b_transparentTelextext );
760 void InputManager::activateTeletext( bool b_enable )
764 if( hasInput() && !var_Change( p_input, "teletext-es", VLC_VAR_GETLIST, &list, &text ) )
766 if( list.p_list->i_count > 0 )
768 /* Prefer the page 100 if it is present */
770 for( i = 0; i < text.p_list->i_count; i++ )
772 /* The description is the page number as a string */
773 const char *psz_page = text.p_list->p_values[i].psz_string;
774 if( psz_page && !strcmp( psz_page, "100" ) )
777 if( i >= list.p_list->i_count )
779 var_SetInteger( p_input, "spu-es", b_enable ? list.p_list->p_values[i].i_int : -1 );
781 var_FreeList( &list, &text );
785 void InputManager::reverse()
789 float f_rate = var_GetFloat( p_input, "rate" );
790 var_SetFloat( p_input, "rate", -f_rate );
794 void InputManager::slower()
797 var_TriggerCallback( p_input, "rate-slower" );
800 void InputManager::faster()
803 var_TriggerCallback( p_input, "rate-faster" );
806 void InputManager::littlefaster()
808 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_RATE_FASTER_FINE );
811 void InputManager::littleslower()
813 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_RATE_SLOWER_FINE );
816 void InputManager::normalRate()
819 var_SetFloat( p_input, "rate", 1. );
822 void InputManager::setRate( int new_rate )
825 var_SetFloat( p_input, "rate",
826 (float)INPUT_RATE_DEFAULT / (float)new_rate );
829 void InputManager::jumpFwd()
831 int i_interval = config_GetInt( p_input, "short-jump-size" );
834 mtime_t val = (mtime_t)(i_interval) * 1000000L;
835 var_SetTime( p_input, "time-offset", val );
839 void InputManager::jumpBwd()
841 int i_interval = config_GetInt( p_input, "short-jump-size" );
844 mtime_t val = -1 *(mtime_t)(i_interval) * 1000000L;
845 var_SetTime( p_input, "time-offset", val );
849 void InputManager::setAtoB()
853 timeA = var_GetTime( THEMIM->getInput(), "time" );
857 timeB = var_GetTime( THEMIM->getInput(), "time" );
858 var_SetTime( THEMIM->getInput(), "time" , timeA );
859 CONNECT( this, positionUpdated( float, int, int ),
860 this, AtoBLoop( float, int, int ) );
866 disconnect( this, SIGNAL( positionUpdated( float, int, int ) ),
867 this, SLOT( AtoBLoop( float, int, int ) ) );
869 emit AtoBchanged( (timeA != 0 ), (timeB != 0 ) );
872 /* Function called regularly when in an AtoB loop */
873 void InputManager::AtoBLoop( float, int i_time, int )
877 if( ( i_time >= (int)( timeB/1000000 ) )
878 || ( i_time < (int)( timeA/1000000 ) ) )
879 var_SetTime( THEMIM->getInput(), "time" , timeA );
883 /**********************************************************************
884 * MainInputManager implementation. Wrap an input manager and
885 * take care of updating the main playlist input.
886 * Used in the main playlist Dialog
887 **********************************************************************/
888 MainInputManager * MainInputManager::instance = NULL;
890 MainInputManager::MainInputManager( intf_thread_t *_p_intf )
891 : QObject(NULL), p_intf( _p_intf )
894 im = new InputManager( this, p_intf );
896 var_AddCallback( THEPL, "item-change", ItemChanged, im );
897 var_AddCallback( THEPL, "item-current", PLItemChanged, this );
898 var_AddCallback( THEPL, "activity", PLItemChanged, this );
899 var_AddCallback( THEPL, "playlist-item-append", PLItemAppended, this );
900 var_AddCallback( THEPL, "playlist-item-deleted", PLItemRemoved, this );
901 var_AddCallback( THEPL, "random", RandomChanged, this );
902 var_AddCallback( THEPL, "repeat", RepeatChanged, this );
903 var_AddCallback( THEPL, "loop", LoopChanged, this );
905 var_AddCallback( p_intf->p_libvlc, "volume-change", VolumeChanged, this );
906 var_AddCallback( p_intf->p_libvlc, "volume-muted", SoundMuteChanged, this );
908 /* Warn our embedded IM about input changes */
909 CONNECT( this, inputChanged( input_thread_t * ),
910 im, setInput( input_thread_t * ) );
912 /* emit check if playlist has already started playing */
913 input_thread_t *p_input = playlist_CurrentInput( THEPL );
916 input_item_t *p_item = input_GetItem( p_input );
919 IMEvent *event = new IMEvent( ItemChanged_Type, p_item );
920 customEvent( event );
923 vlc_object_release( p_input );
927 MainInputManager::~MainInputManager()
931 emit inputChanged( NULL );
932 var_DelCallback( p_input, "state", PLItemChanged, this );
933 vlc_object_release( p_input );
936 var_DelCallback( p_intf->p_libvlc, "volume-change", VolumeChanged, this );
937 var_DelCallback( p_intf->p_libvlc, "volume-muted", SoundMuteChanged, this );
939 var_DelCallback( THEPL, "activity", PLItemChanged, this );
940 var_DelCallback( THEPL, "item-change", ItemChanged, im );
942 var_DelCallback( THEPL, "item-current", PLItemChanged, this );
943 var_DelCallback( THEPL, "playlist-item-append", PLItemAppended, this );
944 var_DelCallback( THEPL, "playlist-item-deleted", PLItemRemoved, this );
945 var_DelCallback( THEPL, "random", RandomChanged, this );
946 var_DelCallback( THEPL, "repeat", RepeatChanged, this );
947 var_DelCallback( THEPL, "loop", LoopChanged, this );
951 vout_thread_t* MainInputManager::getVout()
953 return p_input ? input_GetVout( p_input ) : NULL;
956 aout_instance_t * MainInputManager::getAout()
958 return p_input ? input_GetAout( p_input ) : NULL;
961 void MainInputManager::customEvent( QEvent *event )
963 int type = event->type();
967 // msg_Dbg( p_intf, "New MainIM Event of type: %i", type );
970 case VolumeChanged_Type:
971 emit volumeChanged();
973 case SoundMuteChanged_Type:
974 emit soundMuteChanged();
976 case PLItemAppended_Type:
977 plEv = static_cast<PLEvent*>( event );
978 emit playlistItemAppended( plEv->i_item, plEv->i_parent );
980 case PLItemRemoved_Type:
981 plEv = static_cast<PLEvent*>( event );
982 emit playlistItemRemoved( plEv->i_item );
984 case RandomChanged_Type:
985 emit randomChanged( var_GetBool( THEPL, "random" ) );
987 case LoopChanged_Type:
988 case RepeatChanged_Type:
992 if( type != ItemChanged_Type ) return;
995 /* Should be PLItemChanged Event */
996 if( !p_intf->p_sys->b_isDialogProvider )
998 if( p_input && ( p_input->b_dead || !vlc_object_alive (p_input) ) )
1000 emit inputChanged( p_input );
1001 var_DelCallback( p_input, "state", PLItemChanged, this );
1002 vlc_object_release( p_input );
1009 p_input = playlist_CurrentInput(THEPL);
1012 var_AddCallback( p_input, "state", PLItemChanged, this );
1013 emit inputChanged( p_input );
1019 /* remove previous stored p_input */
1022 vlc_object_release( p_input );
1025 /* we are working as a dialogs provider */
1026 playlist_t *p_playlist = pl_Hold( p_intf );
1027 p_input = playlist_CurrentInput( p_playlist );
1030 emit inputChanged( p_input );
1032 pl_Release( p_intf );
1036 /* Playlist Control functions */
1037 void MainInputManager::stop()
1039 playlist_Stop( THEPL );
1042 void MainInputManager::next()
1044 playlist_Next( THEPL );
1047 void MainInputManager::prev()
1049 playlist_Prev( THEPL );
1052 void MainInputManager::togglePlayPause()
1054 /* No input, play */
1056 playlist_Play( THEPL );
1058 getIM()->togglePlayPause();
1061 void MainInputManager::toggleRandom()
1063 var_ToggleBool( THEPL, "random" );
1066 void MainInputManager::notifyRepeatLoop()
1068 int i_value = var_GetBool( THEPL, "loop" ) * REPEAT_ONE
1069 + var_GetBool( THEPL, "repeat" ) * REPEAT_ALL;
1071 emit repeatLoopChanged( i_value );
1074 void MainInputManager::loopRepeatLoopStatus()
1076 /* Toggle Normal -> Loop -> Repeat -> Normal ... */
1077 if( var_GetBool( THEPL, "repeat" ) )
1078 var_SetBool( THEPL, "repeat", false );
1079 else if( var_GetBool( THEPL, "loop" ) )
1081 var_SetBool( THEPL, "loop", false );
1082 var_SetBool( THEPL, "repeat", true );
1085 var_SetBool( THEPL, "loop", true );
1088 void MainInputManager::activatePlayQuit( bool b_exit )
1090 var_SetBool( THEPL, "play-and-exit", b_exit );
1094 /****************************
1095 * Static callbacks for MIM *
1096 ****************************/
1097 static int PLItemChanged( vlc_object_t *p_this, const char *psz_var,
1098 vlc_value_t oldval, vlc_value_t, void *param )
1100 MainInputManager *mim = (MainInputManager*)param;
1102 IMEvent *event = new IMEvent( ItemChanged_Type );
1103 QApplication::postEvent( mim, event );
1107 static int VolumeChanged( vlc_object_t *p_this, const char *psz_var,
1108 vlc_value_t oldval, vlc_value_t newval, void *param )
1110 MainInputManager *mim = (MainInputManager*)param;
1112 IMEvent *event = new IMEvent( VolumeChanged_Type );
1113 QApplication::postEvent( mim, event );
1117 static int SoundMuteChanged( vlc_object_t *p_this, const char *psz_var,
1118 vlc_value_t oldval, vlc_value_t newval, void *param )
1120 MainInputManager *mim = (MainInputManager*)param;
1122 IMEvent *event = new IMEvent( SoundMuteChanged_Type );
1123 QApplication::postEvent( mim, event );
1127 static int PLItemAppended
1128 ( vlc_object_t * obj, const char *var, vlc_value_t old, vlc_value_t cur, void *data )
1130 MainInputManager *mim = static_cast<MainInputManager*>(data);
1131 playlist_add_t *p_add = static_cast<playlist_add_t*>( cur.p_address );
1133 PLEvent *event = new PLEvent( PLItemAppended_Type, p_add->i_item, p_add->i_node );
1134 QApplication::postEvent( mim, event );
1137 static int PLItemRemoved
1138 ( vlc_object_t * obj, const char *var, vlc_value_t old, vlc_value_t cur, void *data )
1140 MainInputManager *mim = static_cast<MainInputManager*>(data);
1142 PLEvent *event = new PLEvent( PLItemRemoved_Type, cur.i_int, 0 );
1143 QApplication::postEvent( mim, event );
1147 static int RandomChanged
1148 ( vlc_object_t * obj, const char *var, vlc_value_t old, vlc_value_t cur, void *data )
1150 MainInputManager *mim = static_cast<MainInputManager*>(data);
1152 IMEvent *event = new IMEvent( RandomChanged_Type );
1153 QApplication::postEvent( mim, event );
1157 /* Probably could be merged with next callback */
1158 static int LoopChanged
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);
1163 IMEvent *event = new IMEvent( LoopChanged_Type );
1164 QApplication::postEvent( mim, event );
1168 static int RepeatChanged
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 IMEvent *event = new IMEvent( RepeatChanged_Type );
1174 QApplication::postEvent( mim, event );