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 );
106 emit statusChanged( PLAYING_S );
113 p_item = input_GetItem( p_input );
119 assert( !p_input_vbi );
120 emit rateChanged( INPUT_RATE_DEFAULT );
124 /* delete Input if it ever existed.
125 Delete the callbacls on input
126 p_input is released once here */
127 void InputManager::delInput()
129 if( !p_input ) return;
130 msg_Dbg( p_intf, "IM: Deleting the input" );
133 i_old_playing_status = END_S;
143 vlc_object_release( p_input_vbi );
147 vlc_object_release( p_input );
150 emit positionUpdated( -1.0, 0 ,0 );
151 emit rateChanged( INPUT_RATE_DEFAULT ); /* TODO: Do we want this ? */
152 emit nameChanged( "" );
153 emit chapterChanged( 0 );
154 emit titleChanged( 0 );
155 emit statusChanged( END_S );
157 emit teletextPossible( false );
158 emit AtoBchanged( false, false );
159 emit voutChanged( false );
160 emit voutListChanged( NULL, 0 );
162 /* Reset all InfoPanels but stats */
163 emit artChanged( NULL );
164 emit infoChanged( NULL );
165 emit currentMetaChanged( (input_item_t *)NULL );
167 emit encryptionChanged( false );
168 emit recordingStateChanged( false );
171 /* Convert the event from the callbacks in actions */
172 void InputManager::customEvent( QEvent *event )
174 int i_type = event->type();
175 IMEvent *ple = static_cast<IMEvent *>(event);
177 if( i_type == ItemChanged_Type )
178 UpdateMeta( ple->p_item );
186 case PositionUpdate_Type:
189 case StatisticsUpdate_Type:
192 case ItemChanged_Type:
193 /* Ignore ItemChanged_Type event that does not apply to our input */
194 if( p_item == ple->p_item )
199 /* Update duration of file */
202 case ItemStateChanged_Type:
203 // TODO: Fusion with above state
206 // UpdateNavigation(); This shouldn't be useful now
207 // UpdateTeletext(); Same
209 case NameChanged_Type:
212 case MetaChanged_Type:
214 UpdateName(); /* Needed for NowPlaying */
215 UpdateArt(); /* Art is part of meta in the core */
217 case InfoChanged_Type:
220 case ItemTitleChanged_Type:
222 UpdateName(); /* Display the name of the Chapter, if exists */
224 case ItemRateChanged_Type:
227 case ItemEsChanged_Type:
229 // We don't do anything ES related. Why ?
231 case ItemTeletextChanged_Type:
234 case InterfaceVoutUpdate_Type:
237 case SynchroChanged_Type:
238 emit synchroChanged();
240 case CachingEvent_Type:
243 case BookmarksChanged_Type:
244 emit bookmarksChanged();
246 case InterfaceAoutUpdate_Type:
249 case RecordingEvent_Type:
252 case ProgramChanged_Type:
253 UpdateProgramEvent();
256 msg_Warn( p_intf, "This shouldn't happen: %i", i_type );
261 /* Add the callbacks on Input. Self explanatory */
262 inline void InputManager::addCallbacks()
264 var_AddCallback( p_input, "intf-event", InputEvent, this );
267 /* Delete the callbacks on Input. Self explanatory */
268 inline void InputManager::delCallbacks()
270 var_DelCallback( p_input, "intf-event", InputEvent, this );
273 /* Static callbacks for IM */
274 static int ItemChanged( vlc_object_t *p_this, const char *psz_var,
275 vlc_value_t oldval, vlc_value_t newval, void *param )
277 InputManager *im = (InputManager*)param;
278 input_item_t *p_item = static_cast<input_item_t *>(newval.p_address);
280 IMEvent *event = new IMEvent( ItemChanged_Type, p_item );
281 QApplication::postEvent( im, event );
285 static int InputEvent( vlc_object_t *p_this, const char *,
286 vlc_value_t, vlc_value_t newval, void *param )
288 InputManager *im = (InputManager*)param;
291 switch( newval.i_int )
293 case INPUT_EVENT_STATE:
294 event = new IMEvent( ItemStateChanged_Type );
296 case INPUT_EVENT_RATE:
297 event = new IMEvent( ItemRateChanged_Type );
299 case INPUT_EVENT_POSITION:
300 //case INPUT_EVENT_LENGTH:
301 event = new IMEvent( PositionUpdate_Type );
304 case INPUT_EVENT_TITLE:
305 case INPUT_EVENT_CHAPTER:
306 event = new IMEvent( ItemTitleChanged_Type );
310 event = new IMEvent( ItemEsChanged_Type );
312 case INPUT_EVENT_TELETEXT:
313 event = new IMEvent( ItemTeletextChanged_Type );
316 case INPUT_EVENT_STATISTICS:
317 event = new IMEvent( StatisticsUpdate_Type );
320 case INPUT_EVENT_VOUT:
321 event = new IMEvent( InterfaceVoutUpdate_Type );
323 case INPUT_EVENT_AOUT:
324 event = new IMEvent( InterfaceAoutUpdate_Type );
327 case INPUT_EVENT_ITEM_META: /* Codec MetaData + Art */
328 event = new IMEvent( MetaChanged_Type );
330 case INPUT_EVENT_ITEM_INFO: /* Codec Info */
331 event = new IMEvent( InfoChanged_Type );
333 case INPUT_EVENT_ITEM_NAME:
334 event = new IMEvent( NameChanged_Type );
337 case INPUT_EVENT_AUDIO_DELAY:
338 case INPUT_EVENT_SUBTITLE_DELAY:
339 event = new IMEvent( SynchroChanged_Type );
342 case INPUT_EVENT_CACHE:
343 event = new IMEvent( CachingEvent_Type );
346 case INPUT_EVENT_BOOKMARK:
347 event = new IMEvent( BookmarksChanged_Type );
350 case INPUT_EVENT_RECORD:
351 event = new IMEvent( RecordingEvent_Type );
354 case INPUT_EVENT_PROGRAM:
355 /* This is for PID changes */
356 event = new IMEvent( ProgramChanged_Type );
359 case INPUT_EVENT_SIGNAL:
360 /* This is for capture-card signals */
361 /* event = new IMEvent( SignalChanged_Type );
369 QApplication::postEvent( im, event );
373 static int VbiEvent( vlc_object_t *, const char *,
374 vlc_value_t, vlc_value_t, void *param )
376 InputManager *im = (InputManager*)param;
377 IMEvent *event = new IMEvent( ItemTeletextChanged_Type );
379 QApplication::postEvent( im, event );
383 void InputManager::UpdatePosition()
385 /* Update position */
389 i_length = var_GetTime( p_input , "length" ) / 1000000;
390 i_time = var_GetTime( p_input , "time");
391 f_pos = var_GetFloat( p_input , "position" );
392 emit positionUpdated( f_pos, i_time, i_length );
395 void InputManager::UpdateNavigation()
397 /* Update navigation status */
398 vlc_value_t val; val.i_int = 0;
401 var_Change( p_input, "title", VLC_VAR_CHOICESCOUNT, &val, NULL );
405 emit titleChanged( true );
406 msg_Dbg( p_intf, "Title %i", val.i_int );
407 /* p_input != NULL since val.i_int != 0 */
409 var_Change( p_input, "chapter", VLC_VAR_CHOICESCOUNT, &val, NULL );
410 emit chapterChanged( (val.i_int > 0) );
411 msg_Dbg( p_intf, "Chapter: %i", val.i_int );
414 emit titleChanged( false );
417 void InputManager::UpdateStatus()
419 /* Update playing status */
420 int state = var_GetInteger( p_input, "state" );
421 if( i_old_playing_status != state )
423 i_old_playing_status = state;
424 emit statusChanged( state );
428 void InputManager::UpdateRate()
431 int i_new_rate = INPUT_RATE_DEFAULT / var_GetFloat( p_input, "rate" );
432 if( i_new_rate != i_rate )
436 emit rateChanged( i_rate );
440 void InputManager::UpdateName()
442 /* Update text, name and nowplaying */
445 /* Try to get the Title, then the Name */
446 char *psz_name = input_item_GetTitleFbName( input_GetItem( p_input ) );
448 /* Try to get the nowplaying */
449 char *psz_nowplaying =
450 input_item_GetNowPlaying( input_GetItem( p_input ) );
451 if( !EMPTY_STR( psz_nowplaying ) )
453 text.sprintf( "%s - %s", psz_nowplaying, psz_name );
455 else /* Do it ourself */
457 char *psz_artist = input_item_GetArtist( input_GetItem( p_input ) );
459 if( !EMPTY_STR( psz_artist ) )
460 text.sprintf( "%s - %s", psz_artist, psz_name );
462 text.sprintf( "%s", psz_name );
466 /* Free everything */
468 free( psz_nowplaying );
470 /* If we have Nothing */
473 psz_name = input_item_GetURI( input_GetItem( p_input ) );
474 text.sprintf( "%s", psz_name );
475 text = text.remove( 0, text.lastIndexOf( DIR_SEP ) + 1 );
479 if( oldName != text )
481 emit nameChanged( text );
486 bool InputManager::hasAudio()
491 var_Change( p_input, "audio-es", VLC_VAR_CHOICESCOUNT, &val, NULL );
492 return val.i_int > 0;
497 void InputManager::UpdateTeletext()
501 const bool b_enabled = var_CountChoices( p_input, "teletext-es" ) > 0;
502 const int i_teletext_es = var_GetInteger( p_input, "teletext-es" );
504 /* Teletext is possible. Show the buttons */
505 emit teletextPossible( b_enabled );
507 /* If Teletext is selected */
508 if( b_enabled && i_teletext_es >= 0 )
510 /* Then, find the current page */
512 bool b_transparent = false;
516 var_DelCallback( p_input_vbi, "vbi-page", VbiEvent, this );
517 vlc_object_release( p_input_vbi );
519 p_input_vbi = (vlc_object_t *)
520 vlc_object_find_name( p_input, "zvbi", FIND_CHILD );
524 /* This callback is not remove explicitly, but interfaces
525 * are guaranted to outlive input */
526 var_AddCallback( p_input_vbi, "vbi-page", VbiEvent, this );
528 i_page = var_GetInteger( p_input_vbi, "vbi-page" );
529 b_transparent = !var_GetBool( p_input_vbi, "vbi-opaque" );
531 emit newTelexPageSet( i_page );
532 emit teletextTransparencyActivated( b_transparent );
535 emit teletextActivated( b_enabled && i_teletext_es >= 0 );
539 emit teletextActivated( false );
540 emit teletextPossible( false );
544 void InputManager::UpdateVout()
548 /* Get current vout lists from input */
550 vout_thread_t **pp_vout;
551 if( input_Control( p_input, INPUT_GET_VOUTS, &pp_vout, &i_vout ) )
558 emit voutListChanged( pp_vout, i_vout );
561 bool b_old_video = b_video;
562 b_video = i_vout > 0;
563 if( !!b_old_video != !!b_video )
564 emit voutChanged( b_video );
566 /* Release the vout list */
567 for( int i = 0; i < i_vout; i++ )
568 vlc_object_release( (vlc_object_t*)pp_vout[i] );
572 void InputManager::UpdateAout()
579 void InputManager::UpdateCaching()
581 if(!hasInput()) return;
583 float f_newCache = var_GetFloat ( p_input, "cache" );
584 if( f_newCache != f_cache )
586 f_cache = f_newCache;
588 emit cachingChanged( f_cache );
592 void InputManager::requestArtUpdate()
596 playlist_t *p_playlist = pl_Hold( p_intf );
597 playlist_AskForArtEnqueue( p_playlist, input_GetItem( p_input ), pl_Unlocked );
598 pl_Release( p_intf );
602 /* No input will signal the cover art to update,
603 * let's do it ourself */
608 const QString InputManager::decodeArtURL( input_item_t *p_item )
612 char *psz_art = input_item_GetArtURL( p_item );
614 if( psz_art && !strncmp( psz_art, "file://", 7 ) &&
615 decode_URI( psz_art + 7 ) )
617 url = qfu( psz_art + 8 ); // Remove extra / starting on Win32.
619 url = qfu( psz_art + 7 );
623 url = url.replace( "file://", "" );
624 /* Taglib seems to define a attachment://, It won't work yet */
625 url = url.replace( "attachment://", "" );
629 void InputManager::UpdateArt()
634 url = decodeArtURL( input_GetItem( p_input ) );
636 /* the art hasn't changed, no need to update */
640 /* Update Art meta */
642 emit artChanged( artUrl );
645 inline void InputManager::UpdateStats()
647 emit statisticsUpdated( input_GetItem( p_input ) );
650 inline void InputManager::UpdateMeta( input_item_t *p_item )
652 emit metaChanged( p_item );
655 inline void InputManager::UpdateMeta()
657 emit currentMetaChanged( input_GetItem( p_input ) );
660 inline void InputManager::UpdateInfo()
662 emit infoChanged( input_GetItem( p_input ) );
665 void InputManager::UpdateRecord()
669 emit recordingStateChanged( var_GetBool( p_input, "record" ) );
673 void InputManager::UpdateProgramEvent()
677 bool b_scrambled = var_GetBool( p_input, "program-scrambled" );
678 emit encryptionChanged( b_scrambled );
682 /* User update of the slider */
683 void InputManager::sliderUpdate( float new_pos )
686 var_SetFloat( p_input, "position", new_pos );
689 /* User togglePlayPause */
690 void InputManager::togglePlayPause()
694 int state = var_GetInteger( p_input, "state" );
695 state = ( state != PLAYING_S ) ? PLAYING_S : PAUSE_S;
696 var_SetInteger( p_input, "state", state );
697 emit statusChanged( state );
701 void InputManager::sectionPrev()
705 int i_type = var_Type( p_input, "next-chapter" );
706 var_TriggerCallback( p_input, (i_type & VLC_VAR_TYPE) != 0 ?
707 "prev-chapter":"prev-title" );
711 void InputManager::sectionNext()
715 int i_type = var_Type( p_input, "next-chapter" );
716 var_TriggerCallback( p_input, (i_type & VLC_VAR_TYPE) != 0 ?
717 "next-chapter":"next-title" );
721 void InputManager::sectionMenu()
725 vlc_value_t val, text;
727 if( var_Change( p_input, "title 0", VLC_VAR_GETLIST, &val, &text ) < 0 )
730 /* XXX is it "Root" or "Title" we want here ?" (set 0 by default) */
732 for( int i = 0; i < val.p_list->i_count; i++ )
734 if( !strcmp( text.p_list->p_values[i].psz_string, "Title" ) )
737 var_FreeList( &val, &text );
739 var_SetInteger( p_input, "title 0", root );
747 /* Set a new Teletext Page */
748 void InputManager::telexSetPage( int page )
750 if( hasInput() && p_input_vbi )
752 const int i_teletext_es = var_GetInteger( p_input, "teletext-es" );
754 if( i_teletext_es >= 0 )
756 var_SetInteger( p_input_vbi, "vbi-page", page );
757 emit newTelexPageSet( page );
762 /* Set the transparency on teletext */
763 void InputManager::telexSetTransparency( bool b_transparentTelextext )
765 if( hasInput() && p_input_vbi )
767 var_SetBool( p_input_vbi, "vbi-opaque", !b_transparentTelextext );
768 emit teletextTransparencyActivated( b_transparentTelextext );
772 void InputManager::activateTeletext( bool b_enable )
776 if( hasInput() && !var_Change( p_input, "teletext-es", VLC_VAR_GETLIST, &list, &text ) )
778 if( list.p_list->i_count > 0 )
780 /* Prefer the page 100 if it is present */
782 for( i = 0; i < text.p_list->i_count; i++ )
784 /* The description is the page number as a string */
785 const char *psz_page = text.p_list->p_values[i].psz_string;
786 if( psz_page && !strcmp( psz_page, "100" ) )
789 if( i >= list.p_list->i_count )
791 var_SetInteger( p_input, "spu-es", b_enable ? list.p_list->p_values[i].i_int : -1 );
793 var_FreeList( &list, &text );
797 void InputManager::reverse()
801 float f_rate = var_GetFloat( p_input, "rate" );
802 var_SetFloat( p_input, "rate", -f_rate );
806 void InputManager::slower()
809 var_TriggerCallback( p_input, "rate-slower" );
812 void InputManager::faster()
815 var_TriggerCallback( p_input, "rate-faster" );
818 void InputManager::littlefaster()
820 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_RATE_FASTER_FINE );
823 void InputManager::littleslower()
825 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_RATE_SLOWER_FINE );
828 void InputManager::normalRate()
831 var_SetFloat( p_input, "rate", 1. );
834 void InputManager::setRate( int new_rate )
837 var_SetFloat( p_input, "rate",
838 (float)INPUT_RATE_DEFAULT / (float)new_rate );
841 void InputManager::jumpFwd()
843 int i_interval = var_InheritInteger( p_input, "short-jump-size" );
846 mtime_t val = (mtime_t)(i_interval) * 1000000L;
847 var_SetTime( p_input, "time-offset", val );
851 void InputManager::jumpBwd()
853 int i_interval = var_InheritInteger( p_input, "short-jump-size" );
856 mtime_t val = -1 *(mtime_t)(i_interval) * 1000000L;
857 var_SetTime( p_input, "time-offset", val );
861 void InputManager::setAtoB()
865 timeA = var_GetTime( THEMIM->getInput(), "time" );
869 timeB = var_GetTime( THEMIM->getInput(), "time" );
870 var_SetTime( THEMIM->getInput(), "time" , timeA );
871 CONNECT( this, positionUpdated( float, int64_t, int ),
872 this, AtoBLoop( float, int64_t, int ) );
878 disconnect( this, SIGNAL( positionUpdated( float, int64_t, int ) ),
879 this, SLOT( AtoBLoop( float, int64_t, int ) ) );
881 emit AtoBchanged( (timeA != 0 ), (timeB != 0 ) );
884 /* Function called regularly when in an AtoB loop */
885 void InputManager::AtoBLoop( float, int64_t i_time, int )
889 if( i_time >= timeB || i_time < timeA )
890 var_SetTime( THEMIM->getInput(), "time" , timeA );
894 /**********************************************************************
895 * MainInputManager implementation. Wrap an input manager and
896 * take care of updating the main playlist input.
897 * Used in the main playlist Dialog
898 **********************************************************************/
899 MainInputManager * MainInputManager::instance = NULL;
901 MainInputManager::MainInputManager( intf_thread_t *_p_intf )
902 : QObject(NULL), p_intf( _p_intf )
905 im = new InputManager( this, p_intf );
907 var_AddCallback( THEPL, "item-change", ItemChanged, im );
908 var_AddCallback( THEPL, "item-current", PLItemChanged, this );
909 var_AddCallback( THEPL, "activity", PLItemChanged, this );
910 var_AddCallback( THEPL, "leaf-to-parent", LeafToParent, this );
911 var_AddCallback( THEPL, "playlist-item-append", PLItemAppended, this );
912 var_AddCallback( THEPL, "playlist-item-deleted", PLItemRemoved, this );
913 var_AddCallback( THEPL, "random", RandomChanged, this );
914 var_AddCallback( THEPL, "repeat", RepeatChanged, this );
915 var_AddCallback( THEPL, "loop", LoopChanged, this );
917 var_AddCallback( p_intf->p_libvlc, "volume-change", VolumeChanged, this );
918 var_AddCallback( p_intf->p_libvlc, "volume-muted", SoundMuteChanged, this );
920 /* Warn our embedded IM about input changes */
921 CONNECT( this, inputChanged( input_thread_t * ),
922 im, setInput( input_thread_t * ) );
924 /* emit check if playlist has already started playing */
925 input_thread_t *p_input = playlist_CurrentInput( THEPL );
928 input_item_t *p_item = input_GetItem( p_input );
931 IMEvent *event = new IMEvent( ItemChanged_Type, p_item );
932 customEvent( event );
935 vlc_object_release( p_input );
939 MainInputManager::~MainInputManager()
943 emit inputChanged( NULL );
944 var_DelCallback( p_input, "state", PLItemChanged, this );
945 vlc_object_release( p_input );
948 var_DelCallback( p_intf->p_libvlc, "volume-change", VolumeChanged, this );
949 var_DelCallback( p_intf->p_libvlc, "volume-muted", SoundMuteChanged, this );
951 var_DelCallback( THEPL, "activity", PLItemChanged, this );
952 var_DelCallback( THEPL, "item-change", ItemChanged, im );
953 var_DelCallback( THEPL, "leaf-to-parent", LeafToParent, this );
955 var_DelCallback( THEPL, "item-current", PLItemChanged, this );
956 var_DelCallback( THEPL, "playlist-item-append", PLItemAppended, this );
957 var_DelCallback( THEPL, "playlist-item-deleted", PLItemRemoved, this );
958 var_DelCallback( THEPL, "random", RandomChanged, this );
959 var_DelCallback( THEPL, "repeat", RepeatChanged, this );
960 var_DelCallback( THEPL, "loop", LoopChanged, this );
964 vout_thread_t* MainInputManager::getVout()
966 return p_input ? input_GetVout( p_input ) : NULL;
969 aout_instance_t * MainInputManager::getAout()
971 return p_input ? input_GetAout( p_input ) : NULL;
974 void MainInputManager::customEvent( QEvent *event )
976 int type = event->type();
981 // msg_Dbg( p_intf, "New MainIM Event of type: %i", type );
984 case VolumeChanged_Type:
985 emit volumeChanged();
987 case SoundMuteChanged_Type:
988 emit soundMuteChanged();
990 case PLItemAppended_Type:
991 plEv = static_cast<PLEvent*>( event );
992 emit playlistItemAppended( plEv->i_item, plEv->i_parent );
994 case PLItemRemoved_Type:
995 plEv = static_cast<PLEvent*>( event );
996 emit playlistItemRemoved( plEv->i_item );
998 case RandomChanged_Type:
999 emit randomChanged( var_GetBool( THEPL, "random" ) );
1001 case LoopChanged_Type:
1002 case RepeatChanged_Type:
1005 case LeafToParent_Type:
1006 imEv = static_cast<IMEvent*>( event );
1007 emit leafBecameParent( imEv->p_item );
1009 if( type != ItemChanged_Type ) return;
1012 /* Should be PLItemChanged Event */
1013 if( !p_intf->p_sys->b_isDialogProvider )
1015 if( p_input && ( p_input->b_dead || !vlc_object_alive (p_input) ) )
1017 emit inputChanged( p_input );
1018 var_DelCallback( p_input, "state", PLItemChanged, this );
1019 vlc_object_release( p_input );
1026 p_input = playlist_CurrentInput(THEPL);
1029 var_AddCallback( p_input, "state", PLItemChanged, this );
1030 emit inputChanged( p_input );
1036 /* remove previous stored p_input */
1039 vlc_object_release( p_input );
1042 /* we are working as a dialogs provider */
1043 playlist_t *p_playlist = pl_Hold( p_intf );
1044 p_input = playlist_CurrentInput( p_playlist );
1047 emit inputChanged( p_input );
1049 pl_Release( p_intf );
1053 /* Playlist Control functions */
1054 void MainInputManager::stop()
1056 playlist_Stop( THEPL );
1059 void MainInputManager::next()
1061 playlist_Next( THEPL );
1064 void MainInputManager::prev()
1066 playlist_Prev( THEPL );
1069 void MainInputManager::togglePlayPause()
1071 /* No input, play */
1073 playlist_Play( THEPL );
1075 getIM()->togglePlayPause();
1078 void MainInputManager::play()
1080 /* No input, play */
1082 playlist_Play( THEPL );
1085 if( PLAYING_S != var_GetInteger( p_input, "state" ) )
1087 getIM()->togglePlayPause();
1092 void MainInputManager::pause()
1094 if(p_input && PLAYING_S == var_GetInteger( p_input, "state" ) )
1096 getIM()->togglePlayPause();
1100 void MainInputManager::toggleRandom()
1102 var_ToggleBool( THEPL, "random" );
1105 void MainInputManager::notifyRepeatLoop()
1107 int i_value = var_GetBool( THEPL, "loop" ) * REPEAT_ONE
1108 + var_GetBool( THEPL, "repeat" ) * REPEAT_ALL;
1110 emit repeatLoopChanged( i_value );
1113 void MainInputManager::loopRepeatLoopStatus()
1115 /* Toggle Normal -> Loop -> Repeat -> Normal ... */
1116 if( var_GetBool( THEPL, "repeat" ) )
1117 var_SetBool( THEPL, "repeat", false );
1118 else if( var_GetBool( THEPL, "loop" ) )
1120 var_SetBool( THEPL, "loop", false );
1121 var_SetBool( THEPL, "repeat", true );
1124 var_SetBool( THEPL, "loop", true );
1127 void MainInputManager::activatePlayQuit( bool b_exit )
1129 var_SetBool( THEPL, "play-and-exit", b_exit );
1133 /****************************
1134 * Static callbacks for MIM *
1135 ****************************/
1136 static int PLItemChanged( vlc_object_t *p_this, const char *psz_var,
1137 vlc_value_t oldval, vlc_value_t, void *param )
1139 MainInputManager *mim = (MainInputManager*)param;
1141 IMEvent *event = new IMEvent( ItemChanged_Type );
1142 QApplication::postEvent( mim, event );
1146 static int LeafToParent( vlc_object_t *p_this, const char *psz_var,
1147 vlc_value_t oldval, vlc_value_t newval, void *param )
1149 MainInputManager *mim = (MainInputManager*)param;
1151 IMEvent *event = new IMEvent( LeafToParent_Type,
1152 static_cast<input_item_t*>( newval.p_address ) );
1153 QApplication::postEvent( mim, event );
1157 static int VolumeChanged( vlc_object_t *p_this, const char *psz_var,
1158 vlc_value_t oldval, vlc_value_t newval, void *param )
1160 MainInputManager *mim = (MainInputManager*)param;
1162 IMEvent *event = new IMEvent( VolumeChanged_Type );
1163 QApplication::postEvent( mim, event );
1167 static int SoundMuteChanged( vlc_object_t *p_this, const char *psz_var,
1168 vlc_value_t oldval, vlc_value_t newval, void *param )
1170 MainInputManager *mim = (MainInputManager*)param;
1172 IMEvent *event = new IMEvent( SoundMuteChanged_Type );
1173 QApplication::postEvent( mim, event );
1177 static int PLItemAppended
1178 ( vlc_object_t * obj, const char *var, vlc_value_t old, vlc_value_t cur, void *data )
1180 MainInputManager *mim = static_cast<MainInputManager*>(data);
1181 playlist_add_t *p_add = static_cast<playlist_add_t*>( cur.p_address );
1183 PLEvent *event = new PLEvent( PLItemAppended_Type, p_add->i_item, p_add->i_node );
1184 QApplication::postEvent( mim, event );
1187 static int PLItemRemoved
1188 ( vlc_object_t * obj, const char *var, vlc_value_t old, vlc_value_t cur, void *data )
1190 MainInputManager *mim = static_cast<MainInputManager*>(data);
1192 PLEvent *event = new PLEvent( PLItemRemoved_Type, cur.i_int, 0 );
1193 QApplication::postEvent( mim, event );
1197 static int RandomChanged
1198 ( vlc_object_t * obj, const char *var, vlc_value_t old, vlc_value_t cur, void *data )
1200 MainInputManager *mim = static_cast<MainInputManager*>(data);
1202 IMEvent *event = new IMEvent( RandomChanged_Type );
1203 QApplication::postEvent( mim, event );
1207 /* Probably could be merged with next callback */
1208 static int LoopChanged
1209 ( vlc_object_t * obj, const char *var, vlc_value_t old, vlc_value_t cur, void *data )
1211 MainInputManager *mim = static_cast<MainInputManager*>(data);
1213 IMEvent *event = new IMEvent( LoopChanged_Type );
1214 QApplication::postEvent( mim, event );
1218 static int RepeatChanged
1219 ( vlc_object_t * obj, const char *var, vlc_value_t old, vlc_value_t cur, void *data )
1221 MainInputManager *mim = static_cast<MainInputManager*>(data);
1223 IMEvent *event = new IMEvent( RepeatChanged_Type );
1224 QApplication::postEvent( mim, event );