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>
45 static int ItemChanged( vlc_object_t *, const char *,
46 vlc_value_t, vlc_value_t, void * );
47 static int LeafToParent( vlc_object_t *, const char *,
48 vlc_value_t, vlc_value_t, void * );
49 static int PLItemChanged( vlc_object_t *, const char *,
50 vlc_value_t, vlc_value_t, void * );
51 static int PLItemAppended( vlc_object_t *, const char *,
52 vlc_value_t, vlc_value_t, void * );
53 static int PLItemRemoved( vlc_object_t *, const char *,
54 vlc_value_t, vlc_value_t, void * );
56 static int InputEvent( vlc_object_t *, const char *,
57 vlc_value_t, vlc_value_t, void * );
58 static int VbiEvent( vlc_object_t *, const char *,
59 vlc_value_t, vlc_value_t, void * );
61 /* Ensure arbitratry (not dynamically allocated) event IDs are not in use */
62 static inline void registerAndCheckEventIds( int start, int end )
64 for ( int i=start ; i<=end ; i++ )
65 Q_ASSERT( QEvent::registerEventType( i ) == i ); /* event ID collision ! */
68 /**********************************************************************
69 * InputManager implementation
70 **********************************************************************
71 * The Input Manager can be the main one around the playlist
72 * But can also be used for VLM dialog or similar
73 **********************************************************************/
75 InputManager::InputManager( QObject *parent, intf_thread_t *_p_intf) :
76 QObject( parent ), p_intf( _p_intf )
78 i_old_playing_status = END_S;
88 f_cache = -1.; /* impossible initial value, different from all */
89 registerAndCheckEventIds( IMEvent::PositionUpdate, IMEvent::FullscreenControlPlanHide );
90 registerAndCheckEventIds( PLEvent::PLItemAppended, PLEvent::PLEmpty );
93 InputManager::~InputManager()
98 /* Define the Input used.
99 Add the callbacks on input
100 p_input is held once here */
101 void InputManager::setInput( input_thread_t *_p_input )
105 if( p_input != NULL )
107 msg_Dbg( p_intf, "IM: Setting an input" );
108 vlc_object_hold( p_input );
117 p_item = input_GetItem( p_input );
118 emit rateChanged( var_GetFloat( p_input, "rate" ) );
123 assert( !p_input_vbi );
124 emit rateChanged( var_InheritFloat( p_intf, "rate" ) );
128 /* delete Input if it ever existed.
129 Delete the callbacls on input
130 p_input is released once here */
131 void InputManager::delInput()
133 if( !p_input ) return;
134 msg_Dbg( p_intf, "IM: Deleting the input" );
137 i_old_playing_status = END_S;
148 vlc_object_release( p_input_vbi );
152 vlc_object_release( p_input );
155 emit positionUpdated( -1.0, 0 ,0 );
156 emit rateChanged( var_InheritFloat( p_intf, "rate" ) );
157 emit nameChanged( "" );
158 emit chapterChanged( 0 );
159 emit titleChanged( 0 );
160 emit playingStatusChanged( END_S );
162 emit teletextPossible( false );
163 emit AtoBchanged( false, false );
164 emit voutChanged( false );
165 emit voutListChanged( NULL, 0 );
167 /* Reset all InfoPanels but stats */
168 emit artChanged( NULL );
169 emit infoChanged( NULL );
170 emit currentMetaChanged( (input_item_t *)NULL );
172 emit encryptionChanged( false );
173 emit recordingStateChanged( false );
175 emit cachingChanged( 1 );
178 /* Convert the event from the callbacks in actions */
179 void InputManager::customEvent( QEvent *event )
181 int i_type = event->type();
182 IMEvent *ple = static_cast<IMEvent *>(event);
184 if( i_type == IMEvent::ItemChanged )
185 UpdateMeta( ple->item() );
193 case IMEvent::PositionUpdate:
196 case IMEvent::StatisticsUpdate:
199 case IMEvent::ItemChanged:
200 /* Ignore ItemChanged_Type event that does not apply to our input */
201 if( p_item == ple->item() )
207 /* Update duration of file */
210 case IMEvent::ItemStateChanged:
211 // TODO: Fusion with above state
214 // UpdateNavigation(); This shouldn't be useful now
215 // UpdateTeletext(); Same
217 case IMEvent::NameChanged:
220 case IMEvent::MetaChanged:
222 UpdateName(); /* Needed for NowPlaying */
223 UpdateArt(); /* Art is part of meta in the core */
225 case IMEvent::InfoChanged:
228 case IMEvent::ItemTitleChanged:
230 UpdateName(); /* Display the name of the Chapter, if exists */
232 case IMEvent::ItemRateChanged:
235 case IMEvent::ItemEsChanged:
237 // We don't do anything ES related. Why ?
239 case IMEvent::ItemTeletextChanged:
242 case IMEvent::InterfaceVoutUpdate:
245 case IMEvent::SynchroChanged:
246 emit synchroChanged();
248 case IMEvent::CachingEvent:
251 case IMEvent::BookmarksChanged:
252 emit bookmarksChanged();
254 case IMEvent::InterfaceAoutUpdate:
257 case IMEvent::RecordingEvent:
260 case IMEvent::ProgramChanged:
261 UpdateProgramEvent();
263 case IMEvent::EPGEvent:
267 msg_Warn( p_intf, "This shouldn't happen: %i", i_type );
272 /* Add the callbacks on Input. Self explanatory */
273 inline void InputManager::addCallbacks()
275 var_AddCallback( p_input, "intf-event", InputEvent, this );
276 if( !p_intf->p_sys->b_isDialogProvider )
277 var_AddCallback( p_input, "state", PLItemChanged, THEMIM );
280 /* Delete the callbacks on Input. Self explanatory */
281 inline void InputManager::delCallbacks()
283 if( !p_intf->p_sys->b_isDialogProvider )
284 var_DelCallback( p_input, "state", PLItemChanged, THEMIM );
285 var_DelCallback( p_input, "intf-event", InputEvent, this );
288 /* Static callbacks for IM */
289 static int ItemChanged( vlc_object_t *p_this, const char *psz_var,
290 vlc_value_t oldval, vlc_value_t newval, void *param )
292 VLC_UNUSED( p_this ); VLC_UNUSED( psz_var ); VLC_UNUSED( oldval );
294 InputManager *im = (InputManager*)param;
295 input_item_t *p_item = static_cast<input_item_t *>(newval.p_address);
297 IMEvent *event = new IMEvent( IMEvent::ItemChanged, p_item );
298 QApplication::postEvent( im, event );
302 static int InputEvent( vlc_object_t *p_this, const char *,
303 vlc_value_t, vlc_value_t newval, void *param )
305 VLC_UNUSED( p_this );
307 InputManager *im = (InputManager*)param;
310 switch( newval.i_int )
312 case INPUT_EVENT_STATE:
313 event = new IMEvent( IMEvent::ItemStateChanged );
315 case INPUT_EVENT_RATE:
316 event = new IMEvent( IMEvent::ItemRateChanged );
318 case INPUT_EVENT_POSITION:
319 //case INPUT_EVENT_LENGTH:
320 event = new IMEvent( IMEvent::PositionUpdate );
323 case INPUT_EVENT_TITLE:
324 case INPUT_EVENT_CHAPTER:
325 event = new IMEvent( IMEvent::ItemTitleChanged );
329 event = new IMEvent( IMEvent::ItemEsChanged );
331 case INPUT_EVENT_TELETEXT:
332 event = new IMEvent( IMEvent::ItemTeletextChanged );
335 case INPUT_EVENT_STATISTICS:
336 event = new IMEvent( IMEvent::StatisticsUpdate );
339 case INPUT_EVENT_VOUT:
340 event = new IMEvent( IMEvent::InterfaceVoutUpdate );
342 case INPUT_EVENT_AOUT:
343 event = new IMEvent( IMEvent::InterfaceAoutUpdate );
346 case INPUT_EVENT_ITEM_META: /* Codec MetaData + Art */
347 event = new IMEvent( IMEvent::MetaChanged );
349 case INPUT_EVENT_ITEM_INFO: /* Codec Info */
350 event = new IMEvent( IMEvent::InfoChanged );
352 case INPUT_EVENT_ITEM_NAME:
353 event = new IMEvent( IMEvent::NameChanged );
356 case INPUT_EVENT_AUDIO_DELAY:
357 case INPUT_EVENT_SUBTITLE_DELAY:
358 event = new IMEvent( IMEvent::SynchroChanged );
361 case INPUT_EVENT_CACHE:
362 event = new IMEvent( IMEvent::CachingEvent );
365 case INPUT_EVENT_BOOKMARK:
366 event = new IMEvent( IMEvent::BookmarksChanged );
369 case INPUT_EVENT_RECORD:
370 event = new IMEvent( IMEvent::RecordingEvent );
373 case INPUT_EVENT_PROGRAM:
374 /* This is for PID changes */
375 event = new IMEvent( IMEvent::ProgramChanged );
378 case INPUT_EVENT_ITEM_EPG:
379 /* EPG data changed */
380 event = new IMEvent( IMEvent::EPGEvent );
383 case INPUT_EVENT_SIGNAL:
384 /* This is for capture-card signals */
385 /* event = new IMEvent( SignalChanged_Type );
393 QApplication::postEvent( im, event );
397 static int VbiEvent( vlc_object_t *, const char *,
398 vlc_value_t, vlc_value_t, void *param )
400 InputManager *im = (InputManager*)param;
401 IMEvent *event = new IMEvent( IMEvent::ItemTeletextChanged );
403 QApplication::postEvent( im, event );
407 void InputManager::UpdatePosition()
409 /* Update position */
413 i_length = var_GetTime( p_input , "length" ) / CLOCK_FREQ;
414 i_time = var_GetTime( p_input , "time");
415 f_pos = var_GetFloat( p_input , "position" );
416 emit positionUpdated( f_pos, i_time, i_length );
419 void InputManager::UpdateNavigation()
421 /* Update navigation status */
422 vlc_value_t val; val.i_int = 0;
423 vlc_value_t val2; val2.i_int = 0;
426 var_Change( p_input, "title", VLC_VAR_CHOICESCOUNT, &val, NULL );
430 /* p_input != NULL since val.i_int != 0 */
431 var_Change( p_input, "chapter", VLC_VAR_CHOICESCOUNT, &val2, NULL );
433 emit titleChanged( val.i_int > 1 );
434 emit chapterChanged( val2.i_int > 1 );
437 emit chapterChanged( false );
440 emit inputCanSeek( var_GetBool( p_input, "can-seek" ) );
442 emit inputCanSeek( false );
445 void InputManager::UpdateStatus()
447 /* Update playing status */
448 int state = var_GetInteger( p_input, "state" );
449 if( i_old_playing_status != state )
451 i_old_playing_status = state;
452 emit playingStatusChanged( state );
456 void InputManager::UpdateRate()
459 float f_new_rate = var_GetFloat( p_input, "rate" );
460 if( f_new_rate != f_rate )
464 emit rateChanged( f_rate );
468 void InputManager::UpdateName()
472 /* Update text, name and nowplaying */
475 /* Try to get the nowplaying */
476 char *format = var_InheritString( p_intf, "input-title-format" );
477 char *formated = str_format_meta( THEPL, format );
479 name = qfu(formated);
482 /* If we have Nothing */
483 if( name.simplified().isEmpty() )
485 char *uri = input_item_GetURI( input_GetItem( p_input ) );
486 char *file = uri ? strrchr( uri, '/' ) : NULL;
489 decode_URI( ++file );
497 name = name.trimmed();
499 if( oldName != name )
501 emit nameChanged( name );
506 int InputManager::playingStatus()
508 return i_old_playing_status;
511 bool InputManager::hasAudio()
516 var_Change( p_input, "audio-es", VLC_VAR_CHOICESCOUNT, &val, NULL );
517 return val.i_int > 0;
522 bool InputManager::hasVisualisation()
527 audio_output_t *aout = input_GetAout( p_input );
531 char *visual = var_InheritString( aout, "visual" );
532 vlc_object_release( aout );
541 void InputManager::UpdateTeletext()
545 const bool b_enabled = var_CountChoices( p_input, "teletext-es" ) > 0;
546 const int i_teletext_es = var_GetInteger( p_input, "teletext-es" );
548 /* Teletext is possible. Show the buttons */
549 emit teletextPossible( b_enabled );
551 /* If Teletext is selected */
552 if( b_enabled && i_teletext_es >= 0 )
554 /* Then, find the current page */
556 bool b_transparent = false;
560 var_DelCallback( p_input_vbi, "vbi-page", VbiEvent, this );
561 vlc_object_release( p_input_vbi );
564 if( input_GetEsObjects( p_input, i_teletext_es, &p_input_vbi, NULL, NULL ) )
569 /* This callback is not remove explicitly, but interfaces
570 * are guaranted to outlive input */
571 var_AddCallback( p_input_vbi, "vbi-page", VbiEvent, this );
573 i_page = var_GetInteger( p_input_vbi, "vbi-page" );
574 b_transparent = !var_GetBool( p_input_vbi, "vbi-opaque" );
576 emit newTelexPageSet( i_page );
577 emit teletextTransparencyActivated( b_transparent );
580 emit teletextActivated( b_enabled && i_teletext_es >= 0 );
584 emit teletextActivated( false );
585 emit teletextPossible( false );
589 void InputManager::UpdateEPG()
597 void InputManager::UpdateVout()
601 /* Get current vout lists from input */
603 vout_thread_t **pp_vout;
604 if( input_Control( p_input, INPUT_GET_VOUTS, &pp_vout, &i_vout ) )
611 emit voutListChanged( pp_vout, i_vout );
614 bool b_old_video = b_video;
615 b_video = i_vout > 0;
616 if( !!b_old_video != !!b_video )
617 emit voutChanged( b_video );
619 /* Release the vout list */
620 for( size_t i = 0; i < i_vout; i++ )
621 vlc_object_release( (vlc_object_t*)pp_vout[i] );
625 void InputManager::UpdateAout()
632 void InputManager::UpdateCaching()
634 if(!hasInput()) return;
636 float f_newCache = var_GetFloat ( p_input, "cache" );
637 if( f_newCache != f_cache )
639 f_cache = f_newCache;
641 emit cachingChanged( f_cache );
645 void InputManager::requestArtUpdate( input_item_t *p_item )
647 bool b_current_item = false;
648 if ( !p_item && hasInput() )
649 { /* default to current item */
650 p_item = input_GetItem( p_input );
651 b_current_item = true;
656 /* check if it has already been enqueued */
657 if ( p_item->p_meta )
659 int status = vlc_meta_GetStatus( p_item->p_meta );
660 if ( status & ( ITEM_ART_NOTFOUND|ITEM_ART_FETCHED ) )
663 playlist_AskForArtEnqueue( pl_Get(p_intf), p_item );
664 /* No input will signal the cover art to update,
665 * let's do it ourself */
666 if ( b_current_item )
669 emit artChanged( p_item );
673 const QString InputManager::decodeArtURL( input_item_t *p_item )
677 char *psz_art = input_item_GetArtURL( p_item );
680 char *psz = make_path( psz_art );
686 /* Taglib seems to define a attachment://, It won't work yet */
687 url = url.replace( "attachment://", "" );
690 QString path = qfu( psz_art ? psz_art : "" );
695 void InputManager::UpdateArt()
700 url = decodeArtURL( input_GetItem( p_input ) );
702 /* the art hasn't changed, no need to update */
706 /* Update Art meta */
708 emit artChanged( artUrl );
711 void InputManager::setArt( input_item_t *p_item, QString fileUrl )
715 char *psz_cachedir = config_GetUserDir( VLC_CACHE_DIR );
716 QString old_url = THEMIM->getIM()->decodeArtURL( p_item );
717 old_url = QDir( old_url ).canonicalPath();
719 if( old_url.startsWith( QString::fromUtf8( psz_cachedir ) ) )
720 QFile( old_url ).remove(); /* Purge cached artwork */
722 free( psz_cachedir );
724 input_item_SetArtURL( p_item , fileUrl.toUtf8().constData() );
729 inline void InputManager::UpdateStats()
732 emit statisticsUpdated( input_GetItem( p_input ) );
735 inline void InputManager::UpdateMeta( input_item_t *p_item_ )
737 emit metaChanged( p_item_ );
738 emit artChanged( p_item_ );
741 inline void InputManager::UpdateMeta()
744 emit currentMetaChanged( input_GetItem( p_input ) );
747 inline void InputManager::UpdateInfo()
750 emit infoChanged( input_GetItem( p_input ) );
753 void InputManager::UpdateRecord()
757 emit recordingStateChanged( var_GetBool( p_input, "record" ) );
761 void InputManager::UpdateProgramEvent()
765 bool b_scrambled = var_GetBool( p_input, "program-scrambled" );
766 emit encryptionChanged( b_scrambled );
770 /* User update of the slider */
771 void InputManager::sliderUpdate( float new_pos )
774 var_SetFloat( p_input, "position", new_pos );
775 emit seekRequested( new_pos );
778 void InputManager::sectionPrev()
782 int i_type = var_Type( p_input, "next-chapter" );
783 var_TriggerCallback( p_input, (i_type & VLC_VAR_TYPE) != 0 ?
784 "prev-chapter":"prev-title" );
788 void InputManager::sectionNext()
792 int i_type = var_Type( p_input, "next-chapter" );
793 var_TriggerCallback( p_input, (i_type & VLC_VAR_TYPE) != 0 ?
794 "next-chapter":"next-title" );
798 void InputManager::sectionMenu()
802 vlc_value_t val, text;
804 if( var_Change( p_input, "title 0", VLC_VAR_GETLIST, &val, &text ) < 0 )
807 /* XXX is it "Root" or "Title" we want here ?" (set 0 by default) */
809 for( int i = 0; i < val.p_list->i_count; i++ )
811 if( !strcmp( text.p_list->p_values[i].psz_string, "Title" ) )
814 var_FreeList( &val, &text );
816 var_SetInteger( p_input, "title 0", root );
824 /* Set a new Teletext Page */
825 void InputManager::telexSetPage( int page )
827 if( hasInput() && p_input_vbi )
829 const int i_teletext_es = var_GetInteger( p_input, "teletext-es" );
831 if( i_teletext_es >= 0 )
833 var_SetInteger( p_input_vbi, "vbi-page", page );
834 emit newTelexPageSet( page );
839 /* Set the transparency on teletext */
840 void InputManager::telexSetTransparency( bool b_transparentTelextext )
842 if( hasInput() && p_input_vbi )
844 var_SetBool( p_input_vbi, "vbi-opaque", !b_transparentTelextext );
845 emit teletextTransparencyActivated( b_transparentTelextext );
849 void InputManager::activateTeletext( bool b_enable )
853 if( hasInput() && !var_Change( p_input, "teletext-es", VLC_VAR_GETLIST, &list, &text ) )
855 if( list.p_list->i_count > 0 )
857 /* Prefer the page 100 if it is present */
859 for( i = 0; i < text.p_list->i_count; i++ )
861 /* The description is the page number as a string */
862 const char *psz_page = text.p_list->p_values[i].psz_string;
863 if( psz_page && !strcmp( psz_page, "100" ) )
866 if( i >= list.p_list->i_count )
868 var_SetInteger( p_input, "spu-es", b_enable ? list.p_list->p_values[i].i_int : -1 );
870 var_FreeList( &list, &text );
874 void InputManager::reverse()
878 float f_rate_ = var_GetFloat( p_input, "rate" );
879 var_SetFloat( p_input, "rate", -f_rate_ );
883 void InputManager::slower()
885 var_TriggerCallback( THEPL, "rate-slower" );
888 void InputManager::faster()
890 var_TriggerCallback( THEPL, "rate-faster" );
893 void InputManager::littlefaster()
895 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_RATE_FASTER_FINE );
898 void InputManager::littleslower()
900 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_RATE_SLOWER_FINE );
903 void InputManager::normalRate()
905 var_SetFloat( THEPL, "rate", 1. );
908 void InputManager::setRate( int new_rate )
910 var_SetFloat( THEPL, "rate",
911 (float)INPUT_RATE_DEFAULT / (float)new_rate );
914 void InputManager::jumpFwd()
916 int i_interval = var_InheritInteger( p_input, "short-jump-size" );
917 if( i_interval > 0 && hasInput() )
919 mtime_t val = CLOCK_FREQ * i_interval;
920 var_SetTime( p_input, "time-offset", val );
924 void InputManager::jumpBwd()
926 int i_interval = var_InheritInteger( p_input, "short-jump-size" );
927 if( i_interval > 0 && hasInput() )
929 mtime_t val = -CLOCK_FREQ * i_interval;
930 var_SetTime( p_input, "time-offset", val );
934 void InputManager::setAtoB()
938 timeA = var_GetTime( THEMIM->getInput(), "time" );
942 timeB = var_GetTime( THEMIM->getInput(), "time" );
943 var_SetTime( THEMIM->getInput(), "time" , timeA );
944 CONNECT( this, positionUpdated( float, int64_t, int ),
945 this, AtoBLoop( float, int64_t, int ) );
951 disconnect( this, SIGNAL( positionUpdated( float, int64_t, int ) ),
952 this, SLOT( AtoBLoop( float, int64_t, int ) ) );
954 emit AtoBchanged( (timeA != 0 ), (timeB != 0 ) );
957 /* Function called regularly when in an AtoB loop */
958 void InputManager::AtoBLoop( float, int64_t i_time, int )
962 if( i_time >= timeB || i_time < timeA )
963 var_SetTime( THEMIM->getInput(), "time" , timeA );
967 /**********************************************************************
968 * MainInputManager implementation. Wrap an input manager and
969 * take care of updating the main playlist input.
970 * Used in the main playlist Dialog
971 **********************************************************************/
973 MainInputManager::MainInputManager( intf_thread_t *_p_intf )
974 : QObject(NULL), p_intf( _p_intf ),
975 random( VLC_OBJECT(THEPL), "random" ),
976 repeat( VLC_OBJECT(THEPL), "repeat" ), loop( VLC_OBJECT(THEPL), "loop" ),
977 volume( VLC_OBJECT(THEPL), "volume" ), mute( VLC_OBJECT(THEPL), "mute" )
980 im = new InputManager( this, p_intf );
982 var_AddCallback( THEPL, "item-change", ItemChanged, im );
983 var_AddCallback( THEPL, "activity", PLItemChanged, this );
984 var_AddCallback( THEPL, "leaf-to-parent", LeafToParent, this );
985 var_AddCallback( THEPL, "playlist-item-append", PLItemAppended, this );
986 var_AddCallback( THEPL, "playlist-item-deleted", PLItemRemoved, this );
987 random.addCallback( this, SLOT(notifyRandom(bool)) );
988 repeat.addCallback( this, SLOT(notifyRepeatLoop(bool)) );
989 loop.addCallback( this, SLOT(notifyRepeatLoop(bool)) );
991 volume.addCallback( this, SLOT(notifyVolume(float)) );
992 mute.addCallback( this, SLOT(notifyMute(bool)) );
994 /* Warn our embedded IM about input changes */
995 DCONNECT( this, inputChanged( input_thread_t * ),
996 im, setInput( input_thread_t * ) );
998 /* initialize p_input (an input can already be running) */
999 p_input = playlist_CurrentInput( pl_Get(p_intf) );
1001 emit inputChanged( p_input );
1004 MainInputManager::~MainInputManager()
1008 emit inputChanged( NULL );
1009 vlc_object_release( p_input );
1012 var_DelCallback( THEPL, "activity", PLItemChanged, this );
1013 var_DelCallback( THEPL, "item-change", ItemChanged, im );
1014 var_DelCallback( THEPL, "leaf-to-parent", LeafToParent, this );
1016 var_DelCallback( THEPL, "playlist-item-append", PLItemAppended, this );
1017 var_DelCallback( THEPL, "playlist-item-deleted", PLItemRemoved, this );
1020 vout_thread_t* MainInputManager::getVout()
1022 return p_input ? input_GetVout( p_input ) : NULL;
1025 audio_output_t * MainInputManager::getAout()
1027 return playlist_GetAout( THEPL );
1030 void MainInputManager::customEvent( QEvent *event )
1032 int type = event->type();
1036 // msg_Dbg( p_intf, "New MainIM Event of type: %i", type );
1039 case PLEvent::PLItemAppended:
1040 plEv = static_cast<PLEvent*>( event );
1041 emit playlistItemAppended( plEv->getItemId(), plEv->getParentId() );
1043 case PLEvent::PLItemRemoved:
1044 plEv = static_cast<PLEvent*>( event );
1045 emit playlistItemRemoved( plEv->getItemId() );
1047 case PLEvent::PLEmpty:
1048 plEv = static_cast<PLEvent*>( event );
1049 emit playlistNotEmpty( plEv->getItemId() >= 0 );
1051 case PLEvent::LeafToParent:
1052 plEv = static_cast<PLEvent*>( event );
1053 emit leafBecameParent( plEv->getItemId() );
1056 if( type != IMEvent::ItemChanged ) return;
1059 if( p_input != NULL )
1060 vlc_object_release( p_input );
1061 p_input = playlist_CurrentInput( pl_Get(p_intf) );
1062 emit inputChanged( p_input );
1065 /* Playlist Control functions */
1066 void MainInputManager::stop()
1068 playlist_Stop( THEPL );
1071 void MainInputManager::next()
1073 playlist_Next( THEPL );
1076 void MainInputManager::prev()
1078 playlist_Prev( THEPL );
1081 void MainInputManager::prevOrReset()
1083 if( !p_input || var_GetTime( p_input , "time") < 10000 )
1084 playlist_Prev( THEPL );
1086 getIM()->sliderUpdate( 0.0 );
1089 void MainInputManager::togglePlayPause()
1091 /* No input, play */
1093 playlist_Play( THEPL );
1095 playlist_Pause( THEPL );
1098 void MainInputManager::play()
1100 /* No input, play */
1102 playlist_Play( THEPL );
1105 if( PLAYING_S != var_GetInteger( p_input, "state" ) )
1107 playlist_Pause( THEPL );
1112 void MainInputManager::pause()
1114 if(p_input && PLAYING_S == var_GetInteger( p_input, "state" ) )
1116 playlist_Pause( THEPL );
1120 void MainInputManager::toggleRandom()
1122 config_PutInt( p_intf, "random", var_ToggleBool( THEPL, "random" ) );
1125 void MainInputManager::notifyRandom(bool value)
1127 emit randomChanged(value);
1130 void MainInputManager::notifyRepeatLoop(bool)
1132 int i_value = var_GetBool( THEPL, "loop" ) * REPEAT_ALL
1133 + var_GetBool( THEPL, "repeat" ) * REPEAT_ONE;
1135 emit repeatLoopChanged( i_value );
1138 void MainInputManager::loopRepeatLoopStatus()
1140 /* Toggle Normal -> Loop -> Repeat -> Normal ... */
1141 bool loop = var_GetBool( THEPL, "loop" );
1142 bool repeat = var_GetBool( THEPL, "repeat" );
1160 var_SetBool( THEPL, "loop", loop );
1161 var_SetBool( THEPL, "repeat", repeat );
1162 config_PutInt( p_intf, "loop", loop );
1163 config_PutInt( p_intf, "repeat", repeat );
1166 void MainInputManager::activatePlayQuit( bool b_exit )
1168 var_SetBool( THEPL, "play-and-exit", b_exit );
1171 bool MainInputManager::getPlayExitState()
1173 return var_GetBool( THEPL, "play-and-exit" );
1176 bool MainInputManager::hasEmptyPlaylist()
1178 playlist_Lock( THEPL );
1179 bool b_empty = playlist_IsEmpty( THEPL );
1180 playlist_Unlock( THEPL );
1184 /****************************
1185 * Static callbacks for MIM *
1186 ****************************/
1187 static int PLItemChanged( vlc_object_t *p_this, const char *psz_var,
1188 vlc_value_t oldval, vlc_value_t, void *param )
1190 VLC_UNUSED( p_this ); VLC_UNUSED( psz_var ); VLC_UNUSED( oldval );
1192 MainInputManager *mim = (MainInputManager*)param;
1194 IMEvent *event = new IMEvent( IMEvent::ItemChanged );
1195 QApplication::postEvent( mim, event );
1199 static int LeafToParent( vlc_object_t *p_this, const char *psz_var,
1200 vlc_value_t oldval, vlc_value_t newval, void *param )
1202 VLC_UNUSED( p_this ); VLC_UNUSED( psz_var ); VLC_UNUSED( oldval );
1203 MainInputManager *mim = (MainInputManager*)param;
1205 PLEvent *event = new PLEvent( PLEvent::LeafToParent, newval.i_int );
1207 QApplication::postEvent( mim, event );
1211 void MainInputManager::notifyVolume( float volume )
1213 emit volumeChanged( volume );
1216 void MainInputManager::notifyMute( bool mute )
1218 emit soundMuteChanged(mute);
1221 static int PLItemAppended
1222 ( vlc_object_t * obj, const char *var, vlc_value_t old, vlc_value_t cur, void *data )
1224 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( PLEvent::PLItemAppended, p_add->i_item, p_add->i_node );
1229 QApplication::postEvent( mim, event );
1230 event = new PLEvent( PLEvent::PLEmpty, p_add->i_item, 0 );
1231 QApplication::postEvent( mim, event );
1234 static int PLItemRemoved
1235 ( vlc_object_t * obj, const char *var, vlc_value_t old, vlc_value_t cur, void *data )
1237 VLC_UNUSED( var ); VLC_UNUSED( old );
1239 playlist_t *pl = (playlist_t *) obj;
1240 MainInputManager *mim = static_cast<MainInputManager*>(data);
1242 PLEvent *event = new PLEvent( PLEvent::PLItemRemoved, cur.i_int, 0 );
1243 QApplication::postEvent( mim, event );
1244 // can't use playlist_IsEmpty( ) as it isn't true yet
1245 if ( pl->items.i_size == 1 ) // lock is held
1247 event = new PLEvent( PLEvent::PLEmpty, -1, 0 );
1248 QApplication::postEvent( mim, event );