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 *****************************************************************************/
26 #define __STDC_FORMAT_MACROS 1
27 #define __STDC_CONSTANT_MACROS 1
33 #include "input_manager.hpp"
36 #include <vlc_strings.h>
39 #include <QApplication>
43 static int ItemChanged( vlc_object_t *, const char *,
44 vlc_value_t, vlc_value_t, void * );
45 static int LeafToParent( vlc_object_t *, const char *,
46 vlc_value_t, vlc_value_t, void * );
47 static int PLItemChanged( vlc_object_t *, const char *,
48 vlc_value_t, vlc_value_t, void * );
49 static int PLItemAppended( vlc_object_t *, const char *,
50 vlc_value_t, vlc_value_t, void * );
51 static int PLItemRemoved( vlc_object_t *, const char *,
52 vlc_value_t, vlc_value_t, void * );
53 static int VolumeChanged( vlc_object_t *, const char *,
54 vlc_value_t, vlc_value_t, void * );
55 static int SoundMuteChanged( vlc_object_t *, const char *,
56 vlc_value_t, vlc_value_t, void * );
58 static int RandomChanged( vlc_object_t *, const char *,
59 vlc_value_t, vlc_value_t, void * );
60 static int LoopChanged( vlc_object_t *, const char *,
61 vlc_value_t, vlc_value_t, void * );
62 static int RepeatChanged( vlc_object_t *, const char *,
63 vlc_value_t, vlc_value_t, void * );
66 static int InputEvent( vlc_object_t *, const char *,
67 vlc_value_t, vlc_value_t, void * );
68 static int VbiEvent( vlc_object_t *, const char *,
69 vlc_value_t, vlc_value_t, void * );
72 /**********************************************************************
73 * InputManager implementation
74 **********************************************************************
75 * The Input Manager can be the main one around the playlist
76 * But can also be used for VLM dialog or similar
77 **********************************************************************/
79 InputManager::InputManager( QObject *parent, intf_thread_t *_p_intf) :
80 QObject( parent ), p_intf( _p_intf )
82 i_old_playing_status = END_S;
92 f_cache = -1.; /* impossible initial value, different from all */
95 InputManager::~InputManager()
100 /* Define the Input used.
101 Add the callbacks on input
102 p_input is held once here */
103 void InputManager::setInput( input_thread_t *_p_input )
107 if( p_input && !( p_input->b_dead || !vlc_object_alive (p_input) ) )
109 msg_Dbg( p_intf, "IM: Setting an input" );
110 vlc_object_hold( p_input );
119 p_item = input_GetItem( p_input );
120 emit rateChanged( var_GetFloat( p_input, "rate" ) );
126 assert( !p_input_vbi );
127 emit rateChanged( var_InheritFloat( p_intf, "rate" ) );
131 /* delete Input if it ever existed.
132 Delete the callbacls on input
133 p_input is released once here */
134 void InputManager::delInput()
136 if( !p_input ) return;
137 msg_Dbg( p_intf, "IM: Deleting the input" );
140 i_old_playing_status = END_S;
151 vlc_object_release( p_input_vbi );
155 vlc_object_release( p_input );
158 emit positionUpdated( -1.0, 0 ,0 );
159 emit rateChanged( var_InheritFloat( p_intf, "rate" ) );
160 emit nameChanged( "" );
161 emit chapterChanged( 0 );
162 emit titleChanged( 0 );
163 emit playingStatusChanged( END_S );
165 emit teletextPossible( false );
166 emit AtoBchanged( false, false );
167 emit voutChanged( false );
168 emit voutListChanged( NULL, 0 );
170 /* Reset all InfoPanels but stats */
171 emit artChanged( NULL );
172 emit infoChanged( NULL );
173 emit currentMetaChanged( (input_item_t *)NULL );
175 emit encryptionChanged( false );
176 emit recordingStateChanged( false );
178 emit cachingChanged( 1 );
181 /* Convert the event from the callbacks in actions */
182 void InputManager::customEvent( QEvent *event )
184 int i_type = event->type();
185 IMEvent *ple = static_cast<IMEvent *>(event);
187 if( i_type == ItemChanged_Type )
188 UpdateMeta( ple->p_item );
196 case PositionUpdate_Type:
199 case StatisticsUpdate_Type:
202 case ItemChanged_Type:
203 /* Ignore ItemChanged_Type event that does not apply to our input */
204 if( p_item == ple->p_item )
209 /* Update duration of file */
212 case ItemStateChanged_Type:
213 // TODO: Fusion with above state
216 // UpdateNavigation(); This shouldn't be useful now
217 // UpdateTeletext(); Same
219 case NameChanged_Type:
222 case MetaChanged_Type:
224 UpdateName(); /* Needed for NowPlaying */
225 UpdateArt(); /* Art is part of meta in the core */
227 case InfoChanged_Type:
230 case ItemTitleChanged_Type:
232 UpdateName(); /* Display the name of the Chapter, if exists */
234 case ItemRateChanged_Type:
237 case ItemEsChanged_Type:
239 // We don't do anything ES related. Why ?
241 case ItemTeletextChanged_Type:
244 case InterfaceVoutUpdate_Type:
247 case SynchroChanged_Type:
248 emit synchroChanged();
250 case CachingEvent_Type:
253 case BookmarksChanged_Type:
254 emit bookmarksChanged();
256 case InterfaceAoutUpdate_Type:
259 case RecordingEvent_Type:
262 case ProgramChanged_Type:
263 UpdateProgramEvent();
269 msg_Warn( p_intf, "This shouldn't happen: %i", i_type );
274 /* Add the callbacks on Input. Self explanatory */
275 inline void InputManager::addCallbacks()
277 var_AddCallback( p_input, "intf-event", InputEvent, this );
280 /* Delete the callbacks on Input. Self explanatory */
281 inline void InputManager::delCallbacks()
283 var_DelCallback( p_input, "intf-event", InputEvent, this );
286 /* Static callbacks for IM */
287 static int ItemChanged( vlc_object_t *p_this, const char *psz_var,
288 vlc_value_t oldval, vlc_value_t newval, void *param )
290 VLC_UNUSED( p_this ); VLC_UNUSED( psz_var ); VLC_UNUSED( oldval );
292 InputManager *im = (InputManager*)param;
293 input_item_t *p_item = static_cast<input_item_t *>(newval.p_address);
295 IMEvent *event = new IMEvent( ItemChanged_Type, p_item );
296 QApplication::postEvent( im, event );
300 static int InputEvent( vlc_object_t *p_this, const char *,
301 vlc_value_t, vlc_value_t newval, void *param )
303 VLC_UNUSED( p_this );
305 InputManager *im = (InputManager*)param;
308 switch( newval.i_int )
310 case INPUT_EVENT_STATE:
311 event = new IMEvent( ItemStateChanged_Type );
313 case INPUT_EVENT_RATE:
314 event = new IMEvent( ItemRateChanged_Type );
316 case INPUT_EVENT_POSITION:
317 //case INPUT_EVENT_LENGTH:
318 event = new IMEvent( PositionUpdate_Type );
321 case INPUT_EVENT_TITLE:
322 case INPUT_EVENT_CHAPTER:
323 event = new IMEvent( ItemTitleChanged_Type );
327 event = new IMEvent( ItemEsChanged_Type );
329 case INPUT_EVENT_TELETEXT:
330 event = new IMEvent( ItemTeletextChanged_Type );
333 case INPUT_EVENT_STATISTICS:
334 event = new IMEvent( StatisticsUpdate_Type );
337 case INPUT_EVENT_VOUT:
338 event = new IMEvent( InterfaceVoutUpdate_Type );
340 case INPUT_EVENT_AOUT:
341 event = new IMEvent( InterfaceAoutUpdate_Type );
344 case INPUT_EVENT_ITEM_META: /* Codec MetaData + Art */
345 event = new IMEvent( MetaChanged_Type );
347 case INPUT_EVENT_ITEM_INFO: /* Codec Info */
348 event = new IMEvent( InfoChanged_Type );
350 case INPUT_EVENT_ITEM_NAME:
351 event = new IMEvent( NameChanged_Type );
354 case INPUT_EVENT_AUDIO_DELAY:
355 case INPUT_EVENT_SUBTITLE_DELAY:
356 event = new IMEvent( SynchroChanged_Type );
359 case INPUT_EVENT_CACHE:
360 event = new IMEvent( CachingEvent_Type );
363 case INPUT_EVENT_BOOKMARK:
364 event = new IMEvent( BookmarksChanged_Type );
367 case INPUT_EVENT_RECORD:
368 event = new IMEvent( RecordingEvent_Type );
371 case INPUT_EVENT_PROGRAM:
372 /* This is for PID changes */
373 event = new IMEvent( ProgramChanged_Type );
376 case INPUT_EVENT_ITEM_EPG:
377 /* EPG data changed */
378 event = new IMEvent( EPGEvent_Type );
381 case INPUT_EVENT_SIGNAL:
382 /* This is for capture-card signals */
383 /* event = new IMEvent( SignalChanged_Type );
391 QApplication::postEvent( im, event );
395 static int VbiEvent( vlc_object_t *, const char *,
396 vlc_value_t, vlc_value_t, void *param )
398 InputManager *im = (InputManager*)param;
399 IMEvent *event = new IMEvent( ItemTeletextChanged_Type );
401 QApplication::postEvent( im, event );
405 void InputManager::UpdatePosition()
407 /* Update position */
411 i_length = var_GetTime( p_input , "length" ) / CLOCK_FREQ;
412 i_time = var_GetTime( p_input , "time");
413 f_pos = var_GetFloat( p_input , "position" );
414 emit positionUpdated( f_pos, i_time, i_length );
417 void InputManager::UpdateNavigation()
419 /* Update navigation status */
420 vlc_value_t val; val.i_int = 0;
421 vlc_value_t val2; val2.i_int = 0;
424 var_Change( p_input, "title", VLC_VAR_CHOICESCOUNT, &val, NULL );
428 emit titleChanged( true );
429 msg_Dbg( p_intf, "Title %"PRId64, val.i_int );
430 /* p_input != NULL since val.i_int != 0 */
431 var_Change( p_input, "chapter", VLC_VAR_CHOICESCOUNT, &val2, NULL );
432 emit chapterChanged( (val2.i_int > 1) || ( val2.i_int > 0 && val.i_int > 1 ) );
433 msg_Dbg( p_intf, "Chapter: %"PRId64, val2.i_int );
436 emit titleChanged( false );
439 void InputManager::UpdateStatus()
441 /* Update playing status */
442 int state = var_GetInteger( p_input, "state" );
443 if( i_old_playing_status != state )
445 i_old_playing_status = state;
446 emit playingStatusChanged( state );
450 void InputManager::UpdateRate()
453 float f_new_rate = var_GetFloat( p_input, "rate" );
454 if( f_new_rate != f_rate )
458 emit rateChanged( f_rate );
462 void InputManager::UpdateName()
464 /* Update text, name and nowplaying */
467 /* Try to get the nowplaying */
468 char *format = var_InheritString( p_intf, "input-title-format" );
469 char *formated = str_format_meta( p_input, format );
471 name = qfu(formated);
474 /* If we have Nothing */
477 char *uri = input_item_GetURI( input_GetItem( p_input ) );
478 char *file = uri ? strrchr( uri, '/' ) : NULL;
481 decode_URI( ++file );
489 name = name.trimmed();
491 if( oldName != name )
493 emit nameChanged( name );
498 int InputManager::playingStatus()
500 return i_old_playing_status;
503 bool InputManager::hasAudio()
508 var_Change( p_input, "audio-es", VLC_VAR_CHOICESCOUNT, &val, NULL );
509 return val.i_int > 0;
514 bool InputManager::hasVisualisation()
519 audio_output_t *aout = input_GetAout( p_input );
523 char *visual = var_InheritString( aout, "visual" );
524 vlc_object_release( aout );
533 void InputManager::UpdateTeletext()
537 const bool b_enabled = var_CountChoices( p_input, "teletext-es" ) > 0;
538 const int i_teletext_es = var_GetInteger( p_input, "teletext-es" );
540 /* Teletext is possible. Show the buttons */
541 emit teletextPossible( b_enabled );
543 /* If Teletext is selected */
544 if( b_enabled && i_teletext_es >= 0 )
546 /* Then, find the current page */
548 bool b_transparent = false;
552 var_DelCallback( p_input_vbi, "vbi-page", VbiEvent, this );
553 vlc_object_release( p_input_vbi );
556 if( input_GetEsObjects( p_input, i_teletext_es, &p_input_vbi, NULL, NULL ) )
561 /* This callback is not remove explicitly, but interfaces
562 * are guaranted to outlive input */
563 var_AddCallback( p_input_vbi, "vbi-page", VbiEvent, this );
565 i_page = var_GetInteger( p_input_vbi, "vbi-page" );
566 b_transparent = !var_GetBool( p_input_vbi, "vbi-opaque" );
568 emit newTelexPageSet( i_page );
569 emit teletextTransparencyActivated( b_transparent );
572 emit teletextActivated( b_enabled && i_teletext_es >= 0 );
576 emit teletextActivated( false );
577 emit teletextPossible( false );
581 void InputManager::UpdateEPG()
589 void InputManager::UpdateVout()
593 /* Get current vout lists from input */
595 vout_thread_t **pp_vout;
596 if( input_Control( p_input, INPUT_GET_VOUTS, &pp_vout, &i_vout ) )
603 emit voutListChanged( pp_vout, i_vout );
606 bool b_old_video = b_video;
607 b_video = i_vout > 0;
608 if( !!b_old_video != !!b_video )
609 emit voutChanged( b_video );
611 /* Release the vout list */
612 for( size_t i = 0; i < i_vout; i++ )
613 vlc_object_release( (vlc_object_t*)pp_vout[i] );
617 void InputManager::UpdateAout()
624 void InputManager::UpdateCaching()
626 if(!hasInput()) return;
628 float f_newCache = var_GetFloat ( p_input, "cache" );
629 if( f_newCache != f_cache )
631 f_cache = f_newCache;
633 emit cachingChanged( f_cache );
637 void InputManager::requestArtUpdate()
641 playlist_AskForArtEnqueue( pl_Get(p_intf), input_GetItem( p_input ) );
645 /* No input will signal the cover art to update,
646 * let's do it ourself */
651 const QString InputManager::decodeArtURL( input_item_t *p_item )
655 char *psz_art = input_item_GetArtURL( p_item );
658 char *psz = make_path( psz_art );
664 /* Taglib seems to define a attachment://, It won't work yet */
665 url = url.replace( "attachment://", "" );
668 QString path = qfu( psz_art ? psz_art : "" );
673 void InputManager::UpdateArt()
678 url = decodeArtURL( input_GetItem( p_input ) );
680 /* the art hasn't changed, no need to update */
684 /* Update Art meta */
686 emit artChanged( artUrl );
689 inline void InputManager::UpdateStats()
691 emit statisticsUpdated( input_GetItem( p_input ) );
694 inline void InputManager::UpdateMeta( input_item_t *p_item )
696 emit metaChanged( p_item );
699 inline void InputManager::UpdateMeta()
701 emit currentMetaChanged( input_GetItem( p_input ) );
704 inline void InputManager::UpdateInfo()
706 emit infoChanged( input_GetItem( p_input ) );
709 void InputManager::UpdateRecord()
713 emit recordingStateChanged( var_GetBool( p_input, "record" ) );
717 void InputManager::UpdateProgramEvent()
721 bool b_scrambled = var_GetBool( p_input, "program-scrambled" );
722 emit encryptionChanged( b_scrambled );
726 /* User update of the slider */
727 void InputManager::sliderUpdate( float new_pos )
730 var_SetFloat( p_input, "position", new_pos );
731 emit seekRequested( new_pos );
734 /* User togglePlayPause */
735 void InputManager::togglePlayPause()
739 int state = var_GetInteger( p_input, "state" );
740 state = ( state != PLAYING_S ) ? PLAYING_S : PAUSE_S;
741 var_SetInteger( p_input, "state", state );
745 void InputManager::sectionPrev()
749 int i_type = var_Type( p_input, "next-chapter" );
750 var_TriggerCallback( p_input, (i_type & VLC_VAR_TYPE) != 0 ?
751 "prev-chapter":"prev-title" );
755 void InputManager::sectionNext()
759 int i_type = var_Type( p_input, "next-chapter" );
760 var_TriggerCallback( p_input, (i_type & VLC_VAR_TYPE) != 0 ?
761 "next-chapter":"next-title" );
765 void InputManager::sectionMenu()
769 vlc_value_t val, text;
771 if( var_Change( p_input, "title 0", VLC_VAR_GETLIST, &val, &text ) < 0 )
774 /* XXX is it "Root" or "Title" we want here ?" (set 0 by default) */
776 for( int i = 0; i < val.p_list->i_count; i++ )
778 if( !strcmp( text.p_list->p_values[i].psz_string, "Title" ) )
781 var_FreeList( &val, &text );
783 var_SetInteger( p_input, "title 0", root );
791 /* Set a new Teletext Page */
792 void InputManager::telexSetPage( int page )
794 if( hasInput() && p_input_vbi )
796 const int i_teletext_es = var_GetInteger( p_input, "teletext-es" );
798 if( i_teletext_es >= 0 )
800 var_SetInteger( p_input_vbi, "vbi-page", page );
801 emit newTelexPageSet( page );
806 /* Set the transparency on teletext */
807 void InputManager::telexSetTransparency( bool b_transparentTelextext )
809 if( hasInput() && p_input_vbi )
811 var_SetBool( p_input_vbi, "vbi-opaque", !b_transparentTelextext );
812 emit teletextTransparencyActivated( b_transparentTelextext );
816 void InputManager::activateTeletext( bool b_enable )
820 if( hasInput() && !var_Change( p_input, "teletext-es", VLC_VAR_GETLIST, &list, &text ) )
822 if( list.p_list->i_count > 0 )
824 /* Prefer the page 100 if it is present */
826 for( i = 0; i < text.p_list->i_count; i++ )
828 /* The description is the page number as a string */
829 const char *psz_page = text.p_list->p_values[i].psz_string;
830 if( psz_page && !strcmp( psz_page, "100" ) )
833 if( i >= list.p_list->i_count )
835 var_SetInteger( p_input, "spu-es", b_enable ? list.p_list->p_values[i].i_int : -1 );
837 var_FreeList( &list, &text );
841 void InputManager::reverse()
845 float f_rate = var_GetFloat( p_input, "rate" );
846 var_SetFloat( p_input, "rate", -f_rate );
850 void InputManager::slower()
852 var_TriggerCallback( THEPL, "rate-slower" );
855 void InputManager::faster()
857 var_TriggerCallback( THEPL, "rate-faster" );
860 void InputManager::littlefaster()
862 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_RATE_FASTER_FINE );
865 void InputManager::littleslower()
867 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_RATE_SLOWER_FINE );
870 void InputManager::normalRate()
872 var_SetFloat( THEPL, "rate", 1. );
875 void InputManager::setRate( int new_rate )
877 var_SetFloat( THEPL, "rate",
878 (float)INPUT_RATE_DEFAULT / (float)new_rate );
881 void InputManager::jumpFwd()
883 int i_interval = var_InheritInteger( p_input, "short-jump-size" );
886 mtime_t val = CLOCK_FREQ * i_interval;
887 var_SetTime( p_input, "time-offset", val );
891 void InputManager::jumpBwd()
893 int i_interval = var_InheritInteger( p_input, "short-jump-size" );
896 mtime_t val = -CLOCK_FREQ * i_interval;
897 var_SetTime( p_input, "time-offset", val );
901 void InputManager::setAtoB()
905 timeA = var_GetTime( THEMIM->getInput(), "time" );
909 timeB = var_GetTime( THEMIM->getInput(), "time" );
910 var_SetTime( THEMIM->getInput(), "time" , timeA );
911 CONNECT( this, positionUpdated( float, int64_t, int ),
912 this, AtoBLoop( float, int64_t, int ) );
918 disconnect( this, SIGNAL( positionUpdated( float, int64_t, int ) ),
919 this, SLOT( AtoBLoop( float, int64_t, int ) ) );
921 emit AtoBchanged( (timeA != 0 ), (timeB != 0 ) );
924 /* Function called regularly when in an AtoB loop */
925 void InputManager::AtoBLoop( float, int64_t i_time, int )
929 if( i_time >= timeB || i_time < timeA )
930 var_SetTime( THEMIM->getInput(), "time" , timeA );
934 /**********************************************************************
935 * MainInputManager implementation. Wrap an input manager and
936 * take care of updating the main playlist input.
937 * Used in the main playlist Dialog
938 **********************************************************************/
940 MainInputManager::MainInputManager( intf_thread_t *_p_intf )
941 : QObject(NULL), p_intf( _p_intf )
944 im = new InputManager( this, p_intf );
946 var_AddCallback( THEPL, "item-change", ItemChanged, im );
947 var_AddCallback( THEPL, "item-current", PLItemChanged, this );
948 var_AddCallback( THEPL, "activity", PLItemChanged, this );
949 var_AddCallback( THEPL, "leaf-to-parent", LeafToParent, this );
950 var_AddCallback( THEPL, "playlist-item-append", PLItemAppended, this );
951 var_AddCallback( THEPL, "playlist-item-deleted", PLItemRemoved, this );
952 var_AddCallback( THEPL, "random", RandomChanged, this );
953 var_AddCallback( THEPL, "repeat", RepeatChanged, this );
954 var_AddCallback( THEPL, "loop", LoopChanged, this );
956 var_AddCallback( THEPL, "volume", VolumeChanged, this );
957 var_AddCallback( THEPL, "mute", SoundMuteChanged, this );
959 /* Warn our embedded IM about input changes */
960 DCONNECT( this, inputChanged( input_thread_t * ),
961 im, setInput( input_thread_t * ) );
965 MainInputManager::~MainInputManager()
969 emit inputChanged( NULL );
970 var_DelCallback( p_input, "state", PLItemChanged, this );
971 vlc_object_release( p_input );
974 var_DelCallback( THEPL, "volume", VolumeChanged, this );
975 var_DelCallback( THEPL, "mute", SoundMuteChanged, this );
977 var_DelCallback( THEPL, "activity", PLItemChanged, this );
978 var_DelCallback( THEPL, "item-change", ItemChanged, im );
979 var_DelCallback( THEPL, "leaf-to-parent", LeafToParent, this );
981 var_DelCallback( THEPL, "item-current", PLItemChanged, this );
982 var_DelCallback( THEPL, "playlist-item-append", PLItemAppended, this );
983 var_DelCallback( THEPL, "playlist-item-deleted", PLItemRemoved, this );
984 var_DelCallback( THEPL, "random", RandomChanged, this );
985 var_DelCallback( THEPL, "repeat", RepeatChanged, this );
986 var_DelCallback( THEPL, "loop", LoopChanged, this );
990 vout_thread_t* MainInputManager::getVout()
992 return p_input ? input_GetVout( p_input ) : NULL;
995 audio_output_t * MainInputManager::getAout()
997 return p_input ? input_GetAout( p_input ) : NULL;
1000 void MainInputManager::customEvent( QEvent *event )
1002 int type = event->type();
1006 // msg_Dbg( p_intf, "New MainIM Event of type: %i", type );
1009 case VolumeChanged_Type:
1010 emit volumeChanged();
1012 case SoundMuteChanged_Type:
1013 emit soundMuteChanged();
1015 case PLItemAppended_Type:
1016 plEv = static_cast<PLEvent*>( event );
1017 emit playlistItemAppended( plEv->i_item, plEv->i_parent );
1019 case PLItemRemoved_Type:
1020 plEv = static_cast<PLEvent*>( event );
1021 emit playlistItemRemoved( plEv->i_item );
1023 case RandomChanged_Type:
1024 emit randomChanged( var_GetBool( THEPL, "random" ) );
1026 case LoopChanged_Type:
1027 case RepeatChanged_Type:
1030 case LeafToParent_Type:
1031 plEv = static_cast<PLEvent*>( event );
1032 emit leafBecameParent( plEv->i_item );
1035 if( type != ItemChanged_Type ) return;
1038 /* Should be PLItemChanged Event */
1039 if( !p_intf->p_sys->b_isDialogProvider )
1041 if( p_input && ( p_input->b_dead || !vlc_object_alive (p_input) ) )
1043 emit inputChanged( p_input );
1044 var_DelCallback( p_input, "state", PLItemChanged, this );
1045 vlc_object_release( p_input );
1052 p_input = playlist_CurrentInput(THEPL);
1055 var_AddCallback( p_input, "state", PLItemChanged, this );
1056 emit inputChanged( p_input );
1062 /* remove previous stored p_input */
1065 vlc_object_release( p_input );
1068 /* we are working as a dialogs provider */
1069 p_input = playlist_CurrentInput( pl_Get(p_intf) );
1072 emit inputChanged( p_input );
1077 /* Playlist Control functions */
1078 void MainInputManager::stop()
1080 playlist_Stop( THEPL );
1083 void MainInputManager::next()
1085 playlist_Next( THEPL );
1088 void MainInputManager::prev()
1090 playlist_Prev( THEPL );
1093 void MainInputManager::prevOrReset()
1095 if( !p_input || var_GetTime( p_input , "time") < 10000 )
1096 playlist_Prev( THEPL );
1098 getIM()->sliderUpdate( 0.0 );
1101 void MainInputManager::togglePlayPause()
1103 /* No input, play */
1105 playlist_Play( THEPL );
1107 getIM()->togglePlayPause();
1110 void MainInputManager::play()
1112 /* No input, play */
1114 playlist_Play( THEPL );
1117 if( PLAYING_S != var_GetInteger( p_input, "state" ) )
1119 getIM()->togglePlayPause();
1124 void MainInputManager::pause()
1126 if(p_input && PLAYING_S == var_GetInteger( p_input, "state" ) )
1128 getIM()->togglePlayPause();
1132 void MainInputManager::toggleRandom()
1134 var_ToggleBool( THEPL, "random" );
1137 void MainInputManager::notifyRepeatLoop()
1139 int i_value = var_GetBool( THEPL, "loop" ) * REPEAT_ALL
1140 + var_GetBool( THEPL, "repeat" ) * REPEAT_ONE;
1142 emit repeatLoopChanged( i_value );
1145 void MainInputManager::loopRepeatLoopStatus()
1147 /* Toggle Normal -> Loop -> Repeat -> Normal ... */
1148 if( var_GetBool( THEPL, "repeat" ) )
1149 var_SetBool( THEPL, "repeat", false );
1150 else if( var_GetBool( THEPL, "loop" ) )
1152 var_SetBool( THEPL, "loop", false );
1153 var_SetBool( THEPL, "repeat", true );
1156 var_SetBool( THEPL, "loop", true );
1159 void MainInputManager::activatePlayQuit( bool b_exit )
1161 var_SetBool( THEPL, "play-and-exit", b_exit );
1164 bool MainInputManager::getPlayExitState()
1166 return var_GetBool( THEPL, "play-and-exit" );
1169 /****************************
1170 * Static callbacks for MIM *
1171 ****************************/
1172 static int PLItemChanged( vlc_object_t *p_this, const char *psz_var,
1173 vlc_value_t oldval, vlc_value_t, void *param )
1175 VLC_UNUSED( p_this ); VLC_UNUSED( psz_var ); VLC_UNUSED( oldval );
1177 MainInputManager *mim = (MainInputManager*)param;
1179 IMEvent *event = new IMEvent( ItemChanged_Type );
1180 QApplication::postEvent( mim, event );
1184 static int LeafToParent( vlc_object_t *p_this, const char *psz_var,
1185 vlc_value_t oldval, vlc_value_t newval, void *param )
1187 VLC_UNUSED( p_this ); VLC_UNUSED( psz_var ); VLC_UNUSED( oldval );
1188 MainInputManager *mim = (MainInputManager*)param;
1190 PLEvent *event = new PLEvent( LeafToParent_Type, newval.i_int );
1192 QApplication::postEvent( mim, event );
1196 static int VolumeChanged( vlc_object_t *p_this, const char *psz_var,
1197 vlc_value_t oldval, vlc_value_t newval, void *param )
1199 VLC_UNUSED( p_this ); VLC_UNUSED( psz_var ); VLC_UNUSED( oldval ); VLC_UNUSED( newval );
1201 MainInputManager *mim = (MainInputManager*)param;
1203 IMEvent *event = new IMEvent( VolumeChanged_Type );
1204 QApplication::postEvent( mim, event );
1208 static int SoundMuteChanged( vlc_object_t *p_this, const char *psz_var,
1209 vlc_value_t oldval, vlc_value_t newval, void *param )
1211 VLC_UNUSED( p_this ); VLC_UNUSED( psz_var ); VLC_UNUSED( oldval ); VLC_UNUSED( newval );
1213 MainInputManager *mim = (MainInputManager*)param;
1215 IMEvent *event = new IMEvent( SoundMuteChanged_Type );
1216 QApplication::postEvent( mim, event );
1220 static int PLItemAppended
1221 ( vlc_object_t * obj, const char *var, vlc_value_t old, vlc_value_t cur, void *data )
1223 VLC_UNUSED( obj ); VLC_UNUSED( var ); VLC_UNUSED( old );
1225 MainInputManager *mim = static_cast<MainInputManager*>(data);
1226 playlist_add_t *p_add = static_cast<playlist_add_t*>( cur.p_address );
1228 PLEvent *event = new PLEvent( PLItemAppended_Type, p_add->i_item, p_add->i_node );
1229 QApplication::postEvent( mim, event );
1232 static int PLItemRemoved
1233 ( vlc_object_t * obj, const char *var, vlc_value_t old, vlc_value_t cur, void *data )
1235 VLC_UNUSED( obj ); VLC_UNUSED( var ); VLC_UNUSED( old );
1237 MainInputManager *mim = static_cast<MainInputManager*>(data);
1239 PLEvent *event = new PLEvent( PLItemRemoved_Type, cur.i_int, 0 );
1240 QApplication::postEvent( mim, event );
1244 static int RandomChanged
1245 ( vlc_object_t * obj, const char *var, vlc_value_t old, vlc_value_t cur, void *data )
1247 VLC_UNUSED( obj ); VLC_UNUSED( var ); VLC_UNUSED( old ); VLC_UNUSED( cur );
1249 MainInputManager *mim = static_cast<MainInputManager*>(data);
1251 IMEvent *event = new IMEvent( RandomChanged_Type );
1252 QApplication::postEvent( mim, event );
1256 /* Probably could be merged with next callback */
1257 static int LoopChanged
1258 ( vlc_object_t * obj, const char *var, vlc_value_t old, vlc_value_t cur, void *data )
1260 VLC_UNUSED( obj ); VLC_UNUSED( var ); VLC_UNUSED( old ); VLC_UNUSED( cur );
1262 MainInputManager *mim = static_cast<MainInputManager*>(data);
1264 IMEvent *event = new IMEvent( LoopChanged_Type );
1265 QApplication::postEvent( mim, event );
1269 static int RepeatChanged
1270 ( vlc_object_t * obj, const char *var, vlc_value_t old, vlc_value_t cur, void *data )
1272 VLC_UNUSED( obj ); VLC_UNUSED( var ); VLC_UNUSED( old ); VLC_UNUSED( cur );
1274 MainInputManager *mim = static_cast<MainInputManager*>(data);
1276 IMEvent *event = new IMEvent( RepeatChanged_Type );
1277 QApplication::postEvent( mim, event );