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 && !( p_input->b_dead || !vlc_object_alive (p_input) ) )
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" ) );
124 assert( !p_input_vbi );
125 emit rateChanged( var_InheritFloat( p_intf, "rate" ) );
129 /* delete Input if it ever existed.
130 Delete the callbacls on input
131 p_input is released once here */
132 void InputManager::delInput()
134 if( !p_input ) return;
135 msg_Dbg( p_intf, "IM: Deleting the input" );
138 i_old_playing_status = END_S;
149 vlc_object_release( p_input_vbi );
153 vlc_object_release( p_input );
156 emit positionUpdated( -1.0, 0 ,0 );
157 emit rateChanged( var_InheritFloat( p_intf, "rate" ) );
158 emit nameChanged( "" );
159 emit chapterChanged( 0 );
160 emit titleChanged( 0 );
161 emit playingStatusChanged( END_S );
163 emit teletextPossible( false );
164 emit AtoBchanged( false, false );
165 emit voutChanged( false );
166 emit voutListChanged( NULL, 0 );
168 /* Reset all InfoPanels but stats */
169 emit artChanged( NULL );
170 emit infoChanged( NULL );
171 emit currentMetaChanged( (input_item_t *)NULL );
173 emit encryptionChanged( false );
174 emit recordingStateChanged( false );
176 emit cachingChanged( 1 );
179 /* Convert the event from the callbacks in actions */
180 void InputManager::customEvent( QEvent *event )
182 int i_type = event->type();
183 IMEvent *ple = static_cast<IMEvent *>(event);
185 if( i_type == IMEvent::ItemChanged )
186 UpdateMeta( ple->item() );
194 case IMEvent::PositionUpdate:
197 case IMEvent::StatisticsUpdate:
200 case IMEvent::ItemChanged:
201 /* Ignore ItemChanged_Type event that does not apply to our input */
202 if( p_item == ple->item() )
208 /* Update duration of file */
211 case IMEvent::ItemStateChanged:
212 // TODO: Fusion with above state
215 // UpdateNavigation(); This shouldn't be useful now
216 // UpdateTeletext(); Same
218 case IMEvent::NameChanged:
221 case IMEvent::MetaChanged:
223 UpdateName(); /* Needed for NowPlaying */
224 UpdateArt(); /* Art is part of meta in the core */
226 case IMEvent::InfoChanged:
229 case IMEvent::ItemTitleChanged:
231 UpdateName(); /* Display the name of the Chapter, if exists */
233 case IMEvent::ItemRateChanged:
236 case IMEvent::ItemEsChanged:
238 // We don't do anything ES related. Why ?
240 case IMEvent::ItemTeletextChanged:
243 case IMEvent::InterfaceVoutUpdate:
246 case IMEvent::SynchroChanged:
247 emit synchroChanged();
249 case IMEvent::CachingEvent:
252 case IMEvent::BookmarksChanged:
253 emit bookmarksChanged();
255 case IMEvent::InterfaceAoutUpdate:
258 case IMEvent::RecordingEvent:
261 case IMEvent::ProgramChanged:
262 UpdateProgramEvent();
264 case IMEvent::EPGEvent:
268 msg_Warn( p_intf, "This shouldn't happen: %i", i_type );
273 /* Add the callbacks on Input. Self explanatory */
274 inline void InputManager::addCallbacks()
276 var_AddCallback( p_input, "intf-event", InputEvent, this );
279 /* Delete the callbacks on Input. Self explanatory */
280 inline void InputManager::delCallbacks()
282 var_DelCallback( p_input, "intf-event", InputEvent, this );
285 /* Static callbacks for IM */
286 static int ItemChanged( vlc_object_t *p_this, const char *psz_var,
287 vlc_value_t oldval, vlc_value_t newval, void *param )
289 VLC_UNUSED( p_this ); VLC_UNUSED( psz_var ); VLC_UNUSED( oldval );
291 InputManager *im = (InputManager*)param;
292 input_item_t *p_item = static_cast<input_item_t *>(newval.p_address);
294 IMEvent *event = new IMEvent( IMEvent::ItemChanged, p_item );
295 QApplication::postEvent( im, event );
299 static int InputEvent( vlc_object_t *p_this, const char *,
300 vlc_value_t, vlc_value_t newval, void *param )
302 VLC_UNUSED( p_this );
304 InputManager *im = (InputManager*)param;
307 switch( newval.i_int )
309 case INPUT_EVENT_STATE:
310 event = new IMEvent( IMEvent::ItemStateChanged );
312 case INPUT_EVENT_RATE:
313 event = new IMEvent( IMEvent::ItemRateChanged );
315 case INPUT_EVENT_POSITION:
316 //case INPUT_EVENT_LENGTH:
317 event = new IMEvent( IMEvent::PositionUpdate );
320 case INPUT_EVENT_TITLE:
321 case INPUT_EVENT_CHAPTER:
322 event = new IMEvent( IMEvent::ItemTitleChanged );
326 event = new IMEvent( IMEvent::ItemEsChanged );
328 case INPUT_EVENT_TELETEXT:
329 event = new IMEvent( IMEvent::ItemTeletextChanged );
332 case INPUT_EVENT_STATISTICS:
333 event = new IMEvent( IMEvent::StatisticsUpdate );
336 case INPUT_EVENT_VOUT:
337 event = new IMEvent( IMEvent::InterfaceVoutUpdate );
339 case INPUT_EVENT_AOUT:
340 event = new IMEvent( IMEvent::InterfaceAoutUpdate );
343 case INPUT_EVENT_ITEM_META: /* Codec MetaData + Art */
344 event = new IMEvent( IMEvent::MetaChanged );
346 case INPUT_EVENT_ITEM_INFO: /* Codec Info */
347 event = new IMEvent( IMEvent::InfoChanged );
349 case INPUT_EVENT_ITEM_NAME:
350 event = new IMEvent( IMEvent::NameChanged );
353 case INPUT_EVENT_AUDIO_DELAY:
354 case INPUT_EVENT_SUBTITLE_DELAY:
355 event = new IMEvent( IMEvent::SynchroChanged );
358 case INPUT_EVENT_CACHE:
359 event = new IMEvent( IMEvent::CachingEvent );
362 case INPUT_EVENT_BOOKMARK:
363 event = new IMEvent( IMEvent::BookmarksChanged );
366 case INPUT_EVENT_RECORD:
367 event = new IMEvent( IMEvent::RecordingEvent );
370 case INPUT_EVENT_PROGRAM:
371 /* This is for PID changes */
372 event = new IMEvent( IMEvent::ProgramChanged );
375 case INPUT_EVENT_ITEM_EPG:
376 /* EPG data changed */
377 event = new IMEvent( IMEvent::EPGEvent );
380 case INPUT_EVENT_SIGNAL:
381 /* This is for capture-card signals */
382 /* event = new IMEvent( SignalChanged_Type );
390 QApplication::postEvent( im, event );
394 static int VbiEvent( vlc_object_t *, const char *,
395 vlc_value_t, vlc_value_t, void *param )
397 InputManager *im = (InputManager*)param;
398 IMEvent *event = new IMEvent( IMEvent::ItemTeletextChanged );
400 QApplication::postEvent( im, event );
404 void InputManager::UpdatePosition()
406 /* Update position */
410 i_length = var_GetTime( p_input , "length" ) / CLOCK_FREQ;
411 i_time = var_GetTime( p_input , "time");
412 f_pos = var_GetFloat( p_input , "position" );
413 emit positionUpdated( f_pos, i_time, i_length );
416 void InputManager::UpdateNavigation()
418 /* Update navigation status */
419 vlc_value_t val; val.i_int = 0;
420 vlc_value_t val2; val2.i_int = 0;
423 var_Change( p_input, "title", VLC_VAR_CHOICESCOUNT, &val, NULL );
427 /* p_input != NULL since val.i_int != 0 */
428 var_Change( p_input, "chapter", VLC_VAR_CHOICESCOUNT, &val2, NULL );
430 emit titleChanged( val.i_int > 1 );
431 emit chapterChanged( val2.i_int > 1 );
434 emit chapterChanged( false );
437 emit inputCanSeek( var_GetBool( p_input, "can-seek" ) );
439 emit inputCanSeek( false );
442 void InputManager::UpdateStatus()
444 /* Update playing status */
445 int state = var_GetInteger( p_input, "state" );
446 if( i_old_playing_status != state )
448 i_old_playing_status = state;
449 emit playingStatusChanged( state );
453 void InputManager::UpdateRate()
456 float f_new_rate = var_GetFloat( p_input, "rate" );
457 if( f_new_rate != f_rate )
461 emit rateChanged( f_rate );
465 void InputManager::UpdateName()
469 /* Update text, name and nowplaying */
472 /* Try to get the nowplaying */
473 char *format = var_InheritString( p_intf, "input-title-format" );
474 char *formated = str_format_meta( THEPL, format );
476 name = qfu(formated);
479 /* If we have Nothing */
480 if( name.simplified().isEmpty() )
482 char *uri = input_item_GetURI( input_GetItem( p_input ) );
483 char *file = uri ? strrchr( uri, '/' ) : NULL;
486 decode_URI( ++file );
494 name = name.trimmed();
496 if( oldName != name )
498 emit nameChanged( name );
503 int InputManager::playingStatus()
505 return i_old_playing_status;
508 bool InputManager::hasAudio()
513 var_Change( p_input, "audio-es", VLC_VAR_CHOICESCOUNT, &val, NULL );
514 return val.i_int > 0;
519 bool InputManager::hasVisualisation()
524 audio_output_t *aout = input_GetAout( p_input );
528 char *visual = var_InheritString( aout, "visual" );
529 vlc_object_release( aout );
538 void InputManager::UpdateTeletext()
542 const bool b_enabled = var_CountChoices( p_input, "teletext-es" ) > 0;
543 const int i_teletext_es = var_GetInteger( p_input, "teletext-es" );
545 /* Teletext is possible. Show the buttons */
546 emit teletextPossible( b_enabled );
548 /* If Teletext is selected */
549 if( b_enabled && i_teletext_es >= 0 )
551 /* Then, find the current page */
553 bool b_transparent = false;
557 var_DelCallback( p_input_vbi, "vbi-page", VbiEvent, this );
558 vlc_object_release( p_input_vbi );
561 if( input_GetEsObjects( p_input, i_teletext_es, &p_input_vbi, NULL, NULL ) )
566 /* This callback is not remove explicitly, but interfaces
567 * are guaranted to outlive input */
568 var_AddCallback( p_input_vbi, "vbi-page", VbiEvent, this );
570 i_page = var_GetInteger( p_input_vbi, "vbi-page" );
571 b_transparent = !var_GetBool( p_input_vbi, "vbi-opaque" );
573 emit newTelexPageSet( i_page );
574 emit teletextTransparencyActivated( b_transparent );
577 emit teletextActivated( b_enabled && i_teletext_es >= 0 );
581 emit teletextActivated( false );
582 emit teletextPossible( false );
586 void InputManager::UpdateEPG()
594 void InputManager::UpdateVout()
598 /* Get current vout lists from input */
600 vout_thread_t **pp_vout;
601 if( input_Control( p_input, INPUT_GET_VOUTS, &pp_vout, &i_vout ) )
608 emit voutListChanged( pp_vout, i_vout );
611 bool b_old_video = b_video;
612 b_video = i_vout > 0;
613 if( !!b_old_video != !!b_video )
614 emit voutChanged( b_video );
616 /* Release the vout list */
617 for( size_t i = 0; i < i_vout; i++ )
618 vlc_object_release( (vlc_object_t*)pp_vout[i] );
622 void InputManager::UpdateAout()
629 void InputManager::UpdateCaching()
631 if(!hasInput()) return;
633 float f_newCache = var_GetFloat ( p_input, "cache" );
634 if( f_newCache != f_cache )
636 f_cache = f_newCache;
638 emit cachingChanged( f_cache );
642 void InputManager::requestArtUpdate( input_item_t *p_item )
644 bool b_current_item = false;
645 if ( !p_item && hasInput() )
646 { /* default to current item */
647 p_item = input_GetItem( p_input );
648 b_current_item = true;
653 /* check if it has already been enqueued */
654 if ( p_item->p_meta )
656 int status = vlc_meta_GetStatus( p_item->p_meta );
657 if ( status & ( ITEM_ART_NOTFOUND|ITEM_ART_FETCHED ) )
660 playlist_AskForArtEnqueue( pl_Get(p_intf), p_item );
661 /* No input will signal the cover art to update,
662 * let's do it ourself */
663 if ( b_current_item )
666 emit artChanged( p_item );
670 const QString InputManager::decodeArtURL( input_item_t *p_item )
674 char *psz_art = input_item_GetArtURL( p_item );
677 char *psz = make_path( psz_art );
683 /* Taglib seems to define a attachment://, It won't work yet */
684 url = url.replace( "attachment://", "" );
687 QString path = qfu( psz_art ? psz_art : "" );
692 void InputManager::UpdateArt()
697 url = decodeArtURL( input_GetItem( p_input ) );
699 /* the art hasn't changed, no need to update */
703 /* Update Art meta */
705 emit artChanged( artUrl );
708 void InputManager::setArt( input_item_t *p_item, QString fileUrl )
712 char *psz_cachedir = config_GetUserDir( VLC_CACHE_DIR );
713 QString old_url = THEMIM->getIM()->decodeArtURL( p_item );
714 old_url = QDir( old_url ).canonicalPath();
716 if( old_url.startsWith( QString::fromUtf8( psz_cachedir ) ) )
717 QFile( old_url ).remove(); /* Purge cached artwork */
719 free( psz_cachedir );
721 input_item_SetArtURL( p_item , fileUrl.toUtf8().constData() );
726 inline void InputManager::UpdateStats()
729 emit statisticsUpdated( input_GetItem( p_input ) );
732 inline void InputManager::UpdateMeta( input_item_t *p_item_ )
734 emit metaChanged( p_item_ );
735 emit artChanged( p_item_ );
738 inline void InputManager::UpdateMeta()
741 emit currentMetaChanged( input_GetItem( p_input ) );
744 inline void InputManager::UpdateInfo()
747 emit infoChanged( input_GetItem( p_input ) );
750 void InputManager::UpdateRecord()
754 emit recordingStateChanged( var_GetBool( p_input, "record" ) );
758 void InputManager::UpdateProgramEvent()
762 bool b_scrambled = var_GetBool( p_input, "program-scrambled" );
763 emit encryptionChanged( b_scrambled );
767 /* User update of the slider */
768 void InputManager::sliderUpdate( float new_pos )
771 var_SetFloat( p_input, "position", new_pos );
772 emit seekRequested( new_pos );
775 void InputManager::sectionPrev()
779 int i_type = var_Type( p_input, "next-chapter" );
780 var_TriggerCallback( p_input, (i_type & VLC_VAR_TYPE) != 0 ?
781 "prev-chapter":"prev-title" );
785 void InputManager::sectionNext()
789 int i_type = var_Type( p_input, "next-chapter" );
790 var_TriggerCallback( p_input, (i_type & VLC_VAR_TYPE) != 0 ?
791 "next-chapter":"next-title" );
795 void InputManager::sectionMenu()
799 vlc_value_t val, text;
801 if( var_Change( p_input, "title 0", VLC_VAR_GETLIST, &val, &text ) < 0 )
804 /* XXX is it "Root" or "Title" we want here ?" (set 0 by default) */
806 for( int i = 0; i < val.p_list->i_count; i++ )
808 if( !strcmp( text.p_list->p_values[i].psz_string, "Title" ) )
811 var_FreeList( &val, &text );
813 var_SetInteger( p_input, "title 0", root );
821 /* Set a new Teletext Page */
822 void InputManager::telexSetPage( int page )
824 if( hasInput() && p_input_vbi )
826 const int i_teletext_es = var_GetInteger( p_input, "teletext-es" );
828 if( i_teletext_es >= 0 )
830 var_SetInteger( p_input_vbi, "vbi-page", page );
831 emit newTelexPageSet( page );
836 /* Set the transparency on teletext */
837 void InputManager::telexSetTransparency( bool b_transparentTelextext )
839 if( hasInput() && p_input_vbi )
841 var_SetBool( p_input_vbi, "vbi-opaque", !b_transparentTelextext );
842 emit teletextTransparencyActivated( b_transparentTelextext );
846 void InputManager::activateTeletext( bool b_enable )
850 if( hasInput() && !var_Change( p_input, "teletext-es", VLC_VAR_GETLIST, &list, &text ) )
852 if( list.p_list->i_count > 0 )
854 /* Prefer the page 100 if it is present */
856 for( i = 0; i < text.p_list->i_count; i++ )
858 /* The description is the page number as a string */
859 const char *psz_page = text.p_list->p_values[i].psz_string;
860 if( psz_page && !strcmp( psz_page, "100" ) )
863 if( i >= list.p_list->i_count )
865 var_SetInteger( p_input, "spu-es", b_enable ? list.p_list->p_values[i].i_int : -1 );
867 var_FreeList( &list, &text );
871 void InputManager::reverse()
875 float f_rate_ = var_GetFloat( p_input, "rate" );
876 var_SetFloat( p_input, "rate", -f_rate_ );
880 void InputManager::slower()
882 var_TriggerCallback( THEPL, "rate-slower" );
885 void InputManager::faster()
887 var_TriggerCallback( THEPL, "rate-faster" );
890 void InputManager::littlefaster()
892 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_RATE_FASTER_FINE );
895 void InputManager::littleslower()
897 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_RATE_SLOWER_FINE );
900 void InputManager::normalRate()
902 var_SetFloat( THEPL, "rate", 1. );
905 void InputManager::setRate( int new_rate )
907 var_SetFloat( THEPL, "rate",
908 (float)INPUT_RATE_DEFAULT / (float)new_rate );
911 void InputManager::jumpFwd()
913 int i_interval = var_InheritInteger( p_input, "short-jump-size" );
914 if( i_interval > 0 && hasInput() )
916 mtime_t val = CLOCK_FREQ * i_interval;
917 var_SetTime( p_input, "time-offset", val );
921 void InputManager::jumpBwd()
923 int i_interval = var_InheritInteger( p_input, "short-jump-size" );
924 if( i_interval > 0 && hasInput() )
926 mtime_t val = -CLOCK_FREQ * i_interval;
927 var_SetTime( p_input, "time-offset", val );
931 void InputManager::setAtoB()
935 timeA = var_GetTime( THEMIM->getInput(), "time" );
939 timeB = var_GetTime( THEMIM->getInput(), "time" );
940 var_SetTime( THEMIM->getInput(), "time" , timeA );
941 CONNECT( this, positionUpdated( float, int64_t, int ),
942 this, AtoBLoop( float, int64_t, int ) );
948 disconnect( this, SIGNAL( positionUpdated( float, int64_t, int ) ),
949 this, SLOT( AtoBLoop( float, int64_t, int ) ) );
951 emit AtoBchanged( (timeA != 0 ), (timeB != 0 ) );
954 /* Function called regularly when in an AtoB loop */
955 void InputManager::AtoBLoop( float, int64_t i_time, int )
959 if( i_time >= timeB || i_time < timeA )
960 var_SetTime( THEMIM->getInput(), "time" , timeA );
964 /**********************************************************************
965 * MainInputManager implementation. Wrap an input manager and
966 * take care of updating the main playlist input.
967 * Used in the main playlist Dialog
968 **********************************************************************/
970 MainInputManager::MainInputManager( intf_thread_t *_p_intf )
971 : QObject(NULL), p_intf( _p_intf ),
972 random( VLC_OBJECT(THEPL), "random" ),
973 repeat( VLC_OBJECT(THEPL), "repeat" ), loop( VLC_OBJECT(THEPL), "loop" ),
974 volume( VLC_OBJECT(THEPL), "volume" ), mute( VLC_OBJECT(THEPL), "mute" )
977 im = new InputManager( this, p_intf );
979 var_AddCallback( THEPL, "item-change", ItemChanged, im );
980 var_AddCallback( THEPL, "activity", PLItemChanged, this );
981 var_AddCallback( THEPL, "leaf-to-parent", LeafToParent, this );
982 var_AddCallback( THEPL, "playlist-item-append", PLItemAppended, this );
983 var_AddCallback( THEPL, "playlist-item-deleted", PLItemRemoved, this );
984 random.addCallback( this, SLOT(notifyRandom(bool)) );
985 repeat.addCallback( this, SLOT(notifyRepeatLoop(bool)) );
986 loop.addCallback( this, SLOT(notifyRepeatLoop(bool)) );
988 volume.addCallback( this, SLOT(notifyVolume(float)) );
989 mute.addCallback( this, SLOT(notifyMute(bool)) );
991 /* Warn our embedded IM about input changes */
992 DCONNECT( this, inputChanged( input_thread_t * ),
993 im, setInput( input_thread_t * ) );
995 /* initialize p_input (an input can already be running) */
996 p_input = playlist_CurrentInput( pl_Get(p_intf) );
999 if( !p_intf->p_sys->b_isDialogProvider )
1000 var_AddCallback( p_input, "state", PLItemChanged, this );
1001 emit inputChanged( p_input );
1005 MainInputManager::~MainInputManager()
1009 emit inputChanged( NULL );
1010 var_DelCallback( p_input, "state", PLItemChanged, this );
1011 vlc_object_release( p_input );
1014 var_DelCallback( THEPL, "activity", PLItemChanged, this );
1015 var_DelCallback( THEPL, "item-change", ItemChanged, im );
1016 var_DelCallback( THEPL, "leaf-to-parent", LeafToParent, this );
1018 var_DelCallback( THEPL, "playlist-item-append", PLItemAppended, this );
1019 var_DelCallback( THEPL, "playlist-item-deleted", PLItemRemoved, this );
1022 vout_thread_t* MainInputManager::getVout()
1024 return p_input ? input_GetVout( p_input ) : NULL;
1027 audio_output_t * MainInputManager::getAout()
1029 return playlist_GetAout( THEPL );
1032 void MainInputManager::customEvent( QEvent *event )
1034 int type = event->type();
1038 // msg_Dbg( p_intf, "New MainIM Event of type: %i", type );
1041 case PLEvent::PLItemAppended:
1042 plEv = static_cast<PLEvent*>( event );
1043 emit playlistItemAppended( plEv->getItemId(), plEv->getParentId() );
1045 case PLEvent::PLItemRemoved:
1046 plEv = static_cast<PLEvent*>( event );
1047 emit playlistItemRemoved( plEv->getItemId() );
1049 case PLEvent::PLEmpty:
1050 plEv = static_cast<PLEvent*>( event );
1051 emit playlistNotEmpty( plEv->getItemId() >= 0 );
1053 case PLEvent::LeafToParent:
1054 plEv = static_cast<PLEvent*>( event );
1055 emit leafBecameParent( plEv->getItemId() );
1058 if( type != IMEvent::ItemChanged ) return;
1061 /* Should be PLItemChanged Event */
1062 if( !p_intf->p_sys->b_isDialogProvider )
1064 if( p_input && ( p_input->b_dead || !vlc_object_alive (p_input) ) )
1066 emit inputChanged( p_input );
1067 var_DelCallback( p_input, "state", PLItemChanged, this );
1068 vlc_object_release( p_input );
1075 p_input = playlist_CurrentInput(THEPL);
1078 var_AddCallback( p_input, "state", PLItemChanged, this );
1079 emit inputChanged( p_input );
1085 /* remove previous stored p_input */
1088 vlc_object_release( p_input );
1091 /* we are working as a dialogs provider */
1092 p_input = playlist_CurrentInput( pl_Get(p_intf) );
1095 emit inputChanged( p_input );
1100 /* Playlist Control functions */
1101 void MainInputManager::stop()
1103 playlist_Stop( THEPL );
1106 void MainInputManager::next()
1108 playlist_Next( THEPL );
1111 void MainInputManager::prev()
1113 playlist_Prev( THEPL );
1116 void MainInputManager::prevOrReset()
1118 if( !p_input || var_GetTime( p_input , "time") < 10000 )
1119 playlist_Prev( THEPL );
1121 getIM()->sliderUpdate( 0.0 );
1124 void MainInputManager::togglePlayPause()
1126 /* No input, play */
1128 playlist_Play( THEPL );
1130 playlist_Pause( THEPL );
1133 void MainInputManager::play()
1135 /* No input, play */
1137 playlist_Play( THEPL );
1140 if( PLAYING_S != var_GetInteger( p_input, "state" ) )
1142 playlist_Pause( THEPL );
1147 void MainInputManager::pause()
1149 if(p_input && PLAYING_S == var_GetInteger( p_input, "state" ) )
1151 playlist_Pause( THEPL );
1155 void MainInputManager::toggleRandom()
1157 config_PutInt( p_intf, "random", var_ToggleBool( THEPL, "random" ) );
1160 void MainInputManager::notifyRandom(bool value)
1162 emit randomChanged(value);
1165 void MainInputManager::notifyRepeatLoop(bool)
1167 int i_value = var_GetBool( THEPL, "loop" ) * REPEAT_ALL
1168 + var_GetBool( THEPL, "repeat" ) * REPEAT_ONE;
1170 emit repeatLoopChanged( i_value );
1173 void MainInputManager::loopRepeatLoopStatus()
1175 /* Toggle Normal -> Loop -> Repeat -> Normal ... */
1176 bool loop = var_GetBool( THEPL, "loop" );
1177 bool repeat = var_GetBool( THEPL, "repeat" );
1195 var_SetBool( THEPL, "loop", loop );
1196 var_SetBool( THEPL, "repeat", repeat );
1197 config_PutInt( p_intf, "loop", loop );
1198 config_PutInt( p_intf, "repeat", repeat );
1201 void MainInputManager::activatePlayQuit( bool b_exit )
1203 var_SetBool( THEPL, "play-and-exit", b_exit );
1206 bool MainInputManager::getPlayExitState()
1208 return var_GetBool( THEPL, "play-and-exit" );
1211 bool MainInputManager::hasEmptyPlaylist()
1213 playlist_Lock( THEPL );
1214 bool b_empty = playlist_IsEmpty( THEPL );
1215 playlist_Unlock( THEPL );
1219 /****************************
1220 * Static callbacks for MIM *
1221 ****************************/
1222 static int PLItemChanged( vlc_object_t *p_this, const char *psz_var,
1223 vlc_value_t oldval, vlc_value_t, void *param )
1225 VLC_UNUSED( p_this ); VLC_UNUSED( psz_var ); VLC_UNUSED( oldval );
1227 MainInputManager *mim = (MainInputManager*)param;
1229 IMEvent *event = new IMEvent( IMEvent::ItemChanged );
1230 QApplication::postEvent( mim, event );
1234 static int LeafToParent( vlc_object_t *p_this, const char *psz_var,
1235 vlc_value_t oldval, vlc_value_t newval, void *param )
1237 VLC_UNUSED( p_this ); VLC_UNUSED( psz_var ); VLC_UNUSED( oldval );
1238 MainInputManager *mim = (MainInputManager*)param;
1240 PLEvent *event = new PLEvent( PLEvent::LeafToParent, newval.i_int );
1242 QApplication::postEvent( mim, event );
1246 void MainInputManager::notifyVolume( float volume )
1248 emit volumeChanged( volume );
1251 void MainInputManager::notifyMute( bool mute )
1253 emit soundMuteChanged(mute);
1256 static int PLItemAppended
1257 ( vlc_object_t * obj, const char *var, vlc_value_t old, vlc_value_t cur, void *data )
1259 VLC_UNUSED( obj ); VLC_UNUSED( var ); VLC_UNUSED( old );
1260 MainInputManager *mim = static_cast<MainInputManager*>(data);
1261 playlist_add_t *p_add = static_cast<playlist_add_t*>( cur.p_address );
1263 PLEvent *event = new PLEvent( PLEvent::PLItemAppended, p_add->i_item, p_add->i_node );
1264 QApplication::postEvent( mim, event );
1265 event = new PLEvent( PLEvent::PLEmpty, p_add->i_item, 0 );
1266 QApplication::postEvent( mim, event );
1269 static int PLItemRemoved
1270 ( vlc_object_t * obj, const char *var, vlc_value_t old, vlc_value_t cur, void *data )
1272 VLC_UNUSED( var ); VLC_UNUSED( old );
1274 playlist_t *pl = (playlist_t *) obj;
1275 MainInputManager *mim = static_cast<MainInputManager*>(data);
1277 PLEvent *event = new PLEvent( PLEvent::PLItemRemoved, cur.i_int, 0 );
1278 QApplication::postEvent( mim, event );
1279 // can't use playlist_IsEmpty( ) as it isn't true yet
1280 if ( pl->items.i_size == 1 ) // lock is held
1282 event = new PLEvent( PLEvent::PLEmpty, -1, 0 );
1283 QApplication::postEvent( mim, event );