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>
38 #include <vlc_aout_intf.h>
40 #include <QApplication>
44 static int ItemChanged( vlc_object_t *, const char *,
45 vlc_value_t, vlc_value_t, void * );
46 static int LeafToParent( vlc_object_t *, const char *,
47 vlc_value_t, vlc_value_t, void * );
48 static int PLItemChanged( vlc_object_t *, const char *,
49 vlc_value_t, vlc_value_t, void * );
50 static int PLItemAppended( vlc_object_t *, const char *,
51 vlc_value_t, vlc_value_t, void * );
52 static int PLItemRemoved( vlc_object_t *, const char *,
53 vlc_value_t, vlc_value_t, void * );
54 static int VolumeChanged( vlc_object_t *, const char *,
55 vlc_value_t, vlc_value_t, void * );
56 static int SoundMuteChanged( vlc_object_t *, const char *,
57 vlc_value_t, vlc_value_t, void * );
59 static int InputEvent( vlc_object_t *, const char *,
60 vlc_value_t, vlc_value_t, void * );
61 static int VbiEvent( vlc_object_t *, const char *,
62 vlc_value_t, vlc_value_t, void * );
65 /**********************************************************************
66 * InputManager implementation
67 **********************************************************************
68 * The Input Manager can be the main one around the playlist
69 * But can also be used for VLM dialog or similar
70 **********************************************************************/
72 InputManager::InputManager( QObject *parent, intf_thread_t *_p_intf) :
73 QObject( parent ), p_intf( _p_intf )
75 i_old_playing_status = END_S;
85 f_cache = -1.; /* impossible initial value, different from all */
88 InputManager::~InputManager()
93 /* Define the Input used.
94 Add the callbacks on input
95 p_input is held once here */
96 void InputManager::setInput( input_thread_t *_p_input )
100 if( p_input && !( p_input->b_dead || !vlc_object_alive (p_input) ) )
102 msg_Dbg( p_intf, "IM: Setting an input" );
103 vlc_object_hold( p_input );
112 p_item = input_GetItem( p_input );
113 emit rateChanged( var_GetFloat( p_input, "rate" ) );
119 assert( !p_input_vbi );
120 emit rateChanged( var_InheritFloat( p_intf, "rate" ) );
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;
144 vlc_object_release( p_input_vbi );
148 vlc_object_release( p_input );
151 emit positionUpdated( -1.0, 0 ,0 );
152 emit rateChanged( var_InheritFloat( p_intf, "rate" ) );
153 emit nameChanged( "" );
154 emit chapterChanged( 0 );
155 emit titleChanged( 0 );
156 emit playingStatusChanged( END_S );
158 emit teletextPossible( false );
159 emit AtoBchanged( false, false );
160 emit voutChanged( false );
161 emit voutListChanged( NULL, 0 );
163 /* Reset all InfoPanels but stats */
164 emit artChanged( NULL );
165 emit infoChanged( NULL );
166 emit currentMetaChanged( (input_item_t *)NULL );
168 emit encryptionChanged( false );
169 emit recordingStateChanged( false );
171 emit cachingChanged( 1 );
174 /* Convert the event from the callbacks in actions */
175 void InputManager::customEvent( QEvent *event )
177 int i_type = event->type();
178 IMEvent *ple = static_cast<IMEvent *>(event);
180 if( i_type == ItemChanged_Type )
181 UpdateMeta( ple->p_item );
189 case PositionUpdate_Type:
192 case StatisticsUpdate_Type:
195 case ItemChanged_Type:
196 /* Ignore ItemChanged_Type event that does not apply to our input */
197 if( p_item == ple->p_item )
202 /* Update duration of file */
205 case ItemStateChanged_Type:
206 // TODO: Fusion with above state
209 // UpdateNavigation(); This shouldn't be useful now
210 // UpdateTeletext(); Same
212 case NameChanged_Type:
215 case MetaChanged_Type:
217 UpdateName(); /* Needed for NowPlaying */
218 UpdateArt(); /* Art is part of meta in the core */
220 case InfoChanged_Type:
223 case ItemTitleChanged_Type:
225 UpdateName(); /* Display the name of the Chapter, if exists */
227 case ItemRateChanged_Type:
230 case ItemEsChanged_Type:
232 // We don't do anything ES related. Why ?
234 case ItemTeletextChanged_Type:
237 case InterfaceVoutUpdate_Type:
240 case SynchroChanged_Type:
241 emit synchroChanged();
243 case CachingEvent_Type:
246 case BookmarksChanged_Type:
247 emit bookmarksChanged();
249 case InterfaceAoutUpdate_Type:
252 case RecordingEvent_Type:
255 case ProgramChanged_Type:
256 UpdateProgramEvent();
262 msg_Warn( p_intf, "This shouldn't happen: %i", i_type );
267 /* Add the callbacks on Input. Self explanatory */
268 inline void InputManager::addCallbacks()
270 var_AddCallback( p_input, "intf-event", InputEvent, this );
273 /* Delete the callbacks on Input. Self explanatory */
274 inline void InputManager::delCallbacks()
276 var_DelCallback( p_input, "intf-event", InputEvent, this );
279 /* Static callbacks for IM */
280 static int ItemChanged( vlc_object_t *p_this, const char *psz_var,
281 vlc_value_t oldval, vlc_value_t newval, void *param )
283 VLC_UNUSED( p_this ); VLC_UNUSED( psz_var ); VLC_UNUSED( oldval );
285 InputManager *im = (InputManager*)param;
286 input_item_t *p_item = static_cast<input_item_t *>(newval.p_address);
288 IMEvent *event = new IMEvent( ItemChanged_Type, p_item );
289 QApplication::postEvent( im, event );
293 static int InputEvent( vlc_object_t *p_this, const char *,
294 vlc_value_t, vlc_value_t newval, void *param )
296 VLC_UNUSED( p_this );
298 InputManager *im = (InputManager*)param;
301 switch( newval.i_int )
303 case INPUT_EVENT_STATE:
304 event = new IMEvent( ItemStateChanged_Type );
306 case INPUT_EVENT_RATE:
307 event = new IMEvent( ItemRateChanged_Type );
309 case INPUT_EVENT_POSITION:
310 //case INPUT_EVENT_LENGTH:
311 event = new IMEvent( PositionUpdate_Type );
314 case INPUT_EVENT_TITLE:
315 case INPUT_EVENT_CHAPTER:
316 event = new IMEvent( ItemTitleChanged_Type );
320 event = new IMEvent( ItemEsChanged_Type );
322 case INPUT_EVENT_TELETEXT:
323 event = new IMEvent( ItemTeletextChanged_Type );
326 case INPUT_EVENT_STATISTICS:
327 event = new IMEvent( StatisticsUpdate_Type );
330 case INPUT_EVENT_VOUT:
331 event = new IMEvent( InterfaceVoutUpdate_Type );
333 case INPUT_EVENT_AOUT:
334 event = new IMEvent( InterfaceAoutUpdate_Type );
337 case INPUT_EVENT_ITEM_META: /* Codec MetaData + Art */
338 event = new IMEvent( MetaChanged_Type );
340 case INPUT_EVENT_ITEM_INFO: /* Codec Info */
341 event = new IMEvent( InfoChanged_Type );
343 case INPUT_EVENT_ITEM_NAME:
344 event = new IMEvent( NameChanged_Type );
347 case INPUT_EVENT_AUDIO_DELAY:
348 case INPUT_EVENT_SUBTITLE_DELAY:
349 event = new IMEvent( SynchroChanged_Type );
352 case INPUT_EVENT_CACHE:
353 event = new IMEvent( CachingEvent_Type );
356 case INPUT_EVENT_BOOKMARK:
357 event = new IMEvent( BookmarksChanged_Type );
360 case INPUT_EVENT_RECORD:
361 event = new IMEvent( RecordingEvent_Type );
364 case INPUT_EVENT_PROGRAM:
365 /* This is for PID changes */
366 event = new IMEvent( ProgramChanged_Type );
369 case INPUT_EVENT_ITEM_EPG:
370 /* EPG data changed */
371 event = new IMEvent( EPGEvent_Type );
374 case INPUT_EVENT_SIGNAL:
375 /* This is for capture-card signals */
376 /* event = new IMEvent( SignalChanged_Type );
384 QApplication::postEvent( im, event );
388 static int VbiEvent( vlc_object_t *, const char *,
389 vlc_value_t, vlc_value_t, void *param )
391 InputManager *im = (InputManager*)param;
392 IMEvent *event = new IMEvent( ItemTeletextChanged_Type );
394 QApplication::postEvent( im, event );
398 void InputManager::UpdatePosition()
400 /* Update position */
404 i_length = var_GetTime( p_input , "length" ) / CLOCK_FREQ;
405 i_time = var_GetTime( p_input , "time");
406 f_pos = var_GetFloat( p_input , "position" );
407 emit positionUpdated( f_pos, i_time, i_length );
410 void InputManager::UpdateNavigation()
412 /* Update navigation status */
413 vlc_value_t val; val.i_int = 0;
414 vlc_value_t val2; val2.i_int = 0;
417 var_Change( p_input, "title", VLC_VAR_CHOICESCOUNT, &val, NULL );
421 /* p_input != NULL since val.i_int != 0 */
422 var_Change( p_input, "chapter", VLC_VAR_CHOICESCOUNT, &val2, NULL );
424 emit titleChanged( val.i_int > 1 );
425 emit chapterChanged( val2.i_int > 1 );
428 emit chapterChanged( false );
431 void InputManager::UpdateStatus()
433 /* Update playing status */
434 int state = var_GetInteger( p_input, "state" );
435 if( i_old_playing_status != state )
437 i_old_playing_status = state;
438 emit playingStatusChanged( state );
442 void InputManager::UpdateRate()
445 float f_new_rate = var_GetFloat( p_input, "rate" );
446 if( f_new_rate != f_rate )
450 emit rateChanged( f_rate );
454 void InputManager::UpdateName()
458 /* Update text, name and nowplaying */
461 /* Try to get the nowplaying */
462 char *format = var_InheritString( p_intf, "input-title-format" );
463 char *formated = str_format_meta( p_input, format );
465 name = qfu(formated);
468 /* If we have Nothing */
471 char *uri = input_item_GetURI( input_GetItem( p_input ) );
472 char *file = uri ? strrchr( uri, '/' ) : NULL;
475 decode_URI( ++file );
483 name = name.trimmed();
485 if( oldName != name )
487 emit nameChanged( name );
492 int InputManager::playingStatus()
494 return i_old_playing_status;
497 bool InputManager::hasAudio()
502 var_Change( p_input, "audio-es", VLC_VAR_CHOICESCOUNT, &val, NULL );
503 return val.i_int > 0;
508 bool InputManager::hasVisualisation()
513 audio_output_t *aout = input_GetAout( p_input );
517 char *visual = var_InheritString( aout, "visual" );
518 vlc_object_release( aout );
527 void InputManager::UpdateTeletext()
531 const bool b_enabled = var_CountChoices( p_input, "teletext-es" ) > 0;
532 const int i_teletext_es = var_GetInteger( p_input, "teletext-es" );
534 /* Teletext is possible. Show the buttons */
535 emit teletextPossible( b_enabled );
537 /* If Teletext is selected */
538 if( b_enabled && i_teletext_es >= 0 )
540 /* Then, find the current page */
542 bool b_transparent = false;
546 var_DelCallback( p_input_vbi, "vbi-page", VbiEvent, this );
547 vlc_object_release( p_input_vbi );
550 if( input_GetEsObjects( p_input, i_teletext_es, &p_input_vbi, NULL, NULL ) )
555 /* This callback is not remove explicitly, but interfaces
556 * are guaranted to outlive input */
557 var_AddCallback( p_input_vbi, "vbi-page", VbiEvent, this );
559 i_page = var_GetInteger( p_input_vbi, "vbi-page" );
560 b_transparent = !var_GetBool( p_input_vbi, "vbi-opaque" );
562 emit newTelexPageSet( i_page );
563 emit teletextTransparencyActivated( b_transparent );
566 emit teletextActivated( b_enabled && i_teletext_es >= 0 );
570 emit teletextActivated( false );
571 emit teletextPossible( false );
575 void InputManager::UpdateEPG()
583 void InputManager::UpdateVout()
587 /* Get current vout lists from input */
589 vout_thread_t **pp_vout;
590 if( input_Control( p_input, INPUT_GET_VOUTS, &pp_vout, &i_vout ) )
597 emit voutListChanged( pp_vout, i_vout );
600 bool b_old_video = b_video;
601 b_video = i_vout > 0;
602 if( !!b_old_video != !!b_video )
603 emit voutChanged( b_video );
605 /* Release the vout list */
606 for( size_t i = 0; i < i_vout; i++ )
607 vlc_object_release( (vlc_object_t*)pp_vout[i] );
611 void InputManager::UpdateAout()
618 void InputManager::UpdateCaching()
620 if(!hasInput()) return;
622 float f_newCache = var_GetFloat ( p_input, "cache" );
623 if( f_newCache != f_cache )
625 f_cache = f_newCache;
627 emit cachingChanged( f_cache );
631 void InputManager::requestArtUpdate()
635 playlist_AskForArtEnqueue( pl_Get(p_intf), input_GetItem( p_input ) );
639 /* No input will signal the cover art to update,
640 * let's do it ourself */
645 const QString InputManager::decodeArtURL( input_item_t *p_item )
649 char *psz_art = input_item_GetArtURL( p_item );
652 char *psz = make_path( psz_art );
658 /* Taglib seems to define a attachment://, It won't work yet */
659 url = url.replace( "attachment://", "" );
662 QString path = qfu( psz_art ? psz_art : "" );
667 void InputManager::UpdateArt()
672 url = decodeArtURL( input_GetItem( p_input ) );
674 /* the art hasn't changed, no need to update */
678 /* Update Art meta */
680 emit artChanged( artUrl );
683 inline void InputManager::UpdateStats()
686 emit statisticsUpdated( input_GetItem( p_input ) );
689 inline void InputManager::UpdateMeta( input_item_t *p_item_ )
691 emit metaChanged( p_item_ );
694 inline void InputManager::UpdateMeta()
697 emit currentMetaChanged( input_GetItem( p_input ) );
700 inline void InputManager::UpdateInfo()
703 emit infoChanged( input_GetItem( p_input ) );
706 void InputManager::UpdateRecord()
710 emit recordingStateChanged( var_GetBool( p_input, "record" ) );
714 void InputManager::UpdateProgramEvent()
718 bool b_scrambled = var_GetBool( p_input, "program-scrambled" );
719 emit encryptionChanged( b_scrambled );
723 /* User update of the slider */
724 void InputManager::sliderUpdate( float new_pos )
727 var_SetFloat( p_input, "position", new_pos );
728 emit seekRequested( new_pos );
731 void InputManager::sectionPrev()
735 int i_type = var_Type( p_input, "next-chapter" );
736 var_TriggerCallback( p_input, (i_type & VLC_VAR_TYPE) != 0 ?
737 "prev-chapter":"prev-title" );
741 void InputManager::sectionNext()
745 int i_type = var_Type( p_input, "next-chapter" );
746 var_TriggerCallback( p_input, (i_type & VLC_VAR_TYPE) != 0 ?
747 "next-chapter":"next-title" );
751 void InputManager::sectionMenu()
755 vlc_value_t val, text;
757 if( var_Change( p_input, "title 0", VLC_VAR_GETLIST, &val, &text ) < 0 )
760 /* XXX is it "Root" or "Title" we want here ?" (set 0 by default) */
762 for( int i = 0; i < val.p_list->i_count; i++ )
764 if( !strcmp( text.p_list->p_values[i].psz_string, "Title" ) )
767 var_FreeList( &val, &text );
769 var_SetInteger( p_input, "title 0", root );
777 /* Set a new Teletext Page */
778 void InputManager::telexSetPage( int page )
780 if( hasInput() && p_input_vbi )
782 const int i_teletext_es = var_GetInteger( p_input, "teletext-es" );
784 if( i_teletext_es >= 0 )
786 var_SetInteger( p_input_vbi, "vbi-page", page );
787 emit newTelexPageSet( page );
792 /* Set the transparency on teletext */
793 void InputManager::telexSetTransparency( bool b_transparentTelextext )
795 if( hasInput() && p_input_vbi )
797 var_SetBool( p_input_vbi, "vbi-opaque", !b_transparentTelextext );
798 emit teletextTransparencyActivated( b_transparentTelextext );
802 void InputManager::activateTeletext( bool b_enable )
806 if( hasInput() && !var_Change( p_input, "teletext-es", VLC_VAR_GETLIST, &list, &text ) )
808 if( list.p_list->i_count > 0 )
810 /* Prefer the page 100 if it is present */
812 for( i = 0; i < text.p_list->i_count; i++ )
814 /* The description is the page number as a string */
815 const char *psz_page = text.p_list->p_values[i].psz_string;
816 if( psz_page && !strcmp( psz_page, "100" ) )
819 if( i >= list.p_list->i_count )
821 var_SetInteger( p_input, "spu-es", b_enable ? list.p_list->p_values[i].i_int : -1 );
823 var_FreeList( &list, &text );
827 void InputManager::reverse()
831 float f_rate_ = var_GetFloat( p_input, "rate" );
832 var_SetFloat( p_input, "rate", -f_rate_ );
836 void InputManager::slower()
838 var_TriggerCallback( THEPL, "rate-slower" );
841 void InputManager::faster()
843 var_TriggerCallback( THEPL, "rate-faster" );
846 void InputManager::littlefaster()
848 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_RATE_FASTER_FINE );
851 void InputManager::littleslower()
853 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_RATE_SLOWER_FINE );
856 void InputManager::normalRate()
858 var_SetFloat( THEPL, "rate", 1. );
861 void InputManager::setRate( int new_rate )
863 var_SetFloat( THEPL, "rate",
864 (float)INPUT_RATE_DEFAULT / (float)new_rate );
867 void InputManager::jumpFwd()
869 int i_interval = var_InheritInteger( p_input, "short-jump-size" );
870 if( i_interval > 0 && hasInput() )
872 mtime_t val = CLOCK_FREQ * i_interval;
873 var_SetTime( p_input, "time-offset", val );
877 void InputManager::jumpBwd()
879 int i_interval = var_InheritInteger( p_input, "short-jump-size" );
880 if( i_interval > 0 && hasInput() )
882 mtime_t val = -CLOCK_FREQ * i_interval;
883 var_SetTime( p_input, "time-offset", val );
887 void InputManager::setAtoB()
891 timeA = var_GetTime( THEMIM->getInput(), "time" );
895 timeB = var_GetTime( THEMIM->getInput(), "time" );
896 var_SetTime( THEMIM->getInput(), "time" , timeA );
897 CONNECT( this, positionUpdated( float, int64_t, int ),
898 this, AtoBLoop( float, int64_t, int ) );
904 disconnect( this, SIGNAL( positionUpdated( float, int64_t, int ) ),
905 this, SLOT( AtoBLoop( float, int64_t, int ) ) );
907 emit AtoBchanged( (timeA != 0 ), (timeB != 0 ) );
910 /* Function called regularly when in an AtoB loop */
911 void InputManager::AtoBLoop( float, int64_t i_time, int )
915 if( i_time >= timeB || i_time < timeA )
916 var_SetTime( THEMIM->getInput(), "time" , timeA );
920 /**********************************************************************
921 * MainInputManager implementation. Wrap an input manager and
922 * take care of updating the main playlist input.
923 * Used in the main playlist Dialog
924 **********************************************************************/
926 MainInputManager::MainInputManager( intf_thread_t *_p_intf )
927 : QObject(NULL), p_intf( _p_intf ),
928 random( VLC_OBJECT(THEPL), "random" ),
929 repeat( VLC_OBJECT(THEPL), "repeat" ), loop( VLC_OBJECT(THEPL), "loop" )
932 im = new InputManager( this, p_intf );
934 var_AddCallback( THEPL, "item-change", ItemChanged, im );
935 var_AddCallback( THEPL, "item-current", PLItemChanged, this );
936 var_AddCallback( THEPL, "activity", PLItemChanged, this );
937 var_AddCallback( THEPL, "leaf-to-parent", LeafToParent, this );
938 var_AddCallback( THEPL, "playlist-item-append", PLItemAppended, this );
939 var_AddCallback( THEPL, "playlist-item-deleted", PLItemRemoved, this );
940 random.addCallback( this, SLOT(notifyRandom(bool)) );
941 repeat.addCallback( this, SLOT(notifyRepeatLoop(bool)) );
942 loop.addCallback( this, SLOT(notifyRepeatLoop(bool)) );
944 var_AddCallback( THEPL, "volume", VolumeChanged, this );
945 var_AddCallback( THEPL, "mute", SoundMuteChanged, this );
947 /* Warn our embedded IM about input changes */
948 DCONNECT( this, inputChanged( input_thread_t * ),
949 im, setInput( input_thread_t * ) );
951 /* initialize p_input (an input can already be running) */
952 p_input = playlist_CurrentInput( pl_Get(p_intf) );
955 if( !p_intf->p_sys->b_isDialogProvider )
956 var_AddCallback( p_input, "state", PLItemChanged, this );
957 emit inputChanged( p_input );
961 MainInputManager::~MainInputManager()
965 emit inputChanged( NULL );
966 var_DelCallback( p_input, "state", PLItemChanged, this );
967 vlc_object_release( p_input );
970 var_DelCallback( THEPL, "volume", VolumeChanged, this );
971 var_DelCallback( THEPL, "mute", SoundMuteChanged, this );
973 var_DelCallback( THEPL, "activity", PLItemChanged, this );
974 var_DelCallback( THEPL, "item-change", ItemChanged, im );
975 var_DelCallback( THEPL, "leaf-to-parent", LeafToParent, this );
977 var_DelCallback( THEPL, "item-current", PLItemChanged, this );
978 var_DelCallback( THEPL, "playlist-item-append", PLItemAppended, this );
979 var_DelCallback( THEPL, "playlist-item-deleted", PLItemRemoved, this );
981 /* Save some interface state in configuration, at module quit */
982 config_PutInt( p_intf, "random", var_GetBool( THEPL, "random" ) );
983 config_PutInt( p_intf, "loop", var_GetBool( THEPL, "loop" ) );
984 config_PutInt( p_intf, "repeat", var_GetBool( THEPL, "repeat" ) );
986 if( var_InheritBool( p_intf, "qt-autosave-volume" ) )
987 config_PutInt( p_intf, "volume", aout_VolumeGet( THEPL ) );
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 );
1024 plEv = static_cast<PLEvent*>( event );
1025 emit playlistNotEmpty( plEv->i_item >= 0 );
1027 case LeafToParent_Type:
1028 plEv = static_cast<PLEvent*>( event );
1029 emit leafBecameParent( plEv->i_item );
1032 if( type != ItemChanged_Type ) return;
1035 /* Should be PLItemChanged Event */
1036 if( !p_intf->p_sys->b_isDialogProvider )
1038 if( p_input && ( p_input->b_dead || !vlc_object_alive (p_input) ) )
1040 emit inputChanged( p_input );
1041 var_DelCallback( p_input, "state", PLItemChanged, this );
1042 vlc_object_release( p_input );
1049 p_input = playlist_CurrentInput(THEPL);
1052 var_AddCallback( p_input, "state", PLItemChanged, this );
1053 emit inputChanged( p_input );
1059 /* remove previous stored p_input */
1062 vlc_object_release( p_input );
1065 /* we are working as a dialogs provider */
1066 p_input = playlist_CurrentInput( pl_Get(p_intf) );
1069 emit inputChanged( p_input );
1074 /* Playlist Control functions */
1075 void MainInputManager::stop()
1077 playlist_Stop( THEPL );
1080 void MainInputManager::next()
1082 playlist_Next( THEPL );
1085 void MainInputManager::prev()
1087 playlist_Prev( THEPL );
1090 void MainInputManager::prevOrReset()
1092 if( !p_input || var_GetTime( p_input , "time") < 10000 )
1093 playlist_Prev( THEPL );
1095 getIM()->sliderUpdate( 0.0 );
1098 void MainInputManager::togglePlayPause()
1100 /* No input, play */
1102 playlist_Play( THEPL );
1104 playlist_Pause( THEPL );
1107 void MainInputManager::play()
1109 /* No input, play */
1111 playlist_Play( THEPL );
1114 if( PLAYING_S != var_GetInteger( p_input, "state" ) )
1116 playlist_Pause( THEPL );
1121 void MainInputManager::pause()
1123 if(p_input && PLAYING_S == var_GetInteger( p_input, "state" ) )
1125 playlist_Pause( THEPL );
1129 void MainInputManager::toggleRandom()
1131 var_ToggleBool( THEPL, "random" );
1134 void MainInputManager::notifyRandom(bool value)
1136 emit randomChanged(value);
1139 void MainInputManager::notifyRepeatLoop(bool)
1141 int i_value = var_GetBool( THEPL, "loop" ) * REPEAT_ALL
1142 + var_GetBool( THEPL, "repeat" ) * REPEAT_ONE;
1144 emit repeatLoopChanged( i_value );
1147 void MainInputManager::loopRepeatLoopStatus()
1149 /* Toggle Normal -> Loop -> Repeat -> Normal ... */
1150 if( var_GetBool( THEPL, "repeat" ) )
1151 var_SetBool( THEPL, "repeat", false );
1152 else if( var_GetBool( THEPL, "loop" ) )
1154 var_SetBool( THEPL, "loop", false );
1155 var_SetBool( THEPL, "repeat", true );
1158 var_SetBool( THEPL, "loop", true );
1161 void MainInputManager::activatePlayQuit( bool b_exit )
1163 var_SetBool( THEPL, "play-and-exit", b_exit );
1166 bool MainInputManager::getPlayExitState()
1168 return var_GetBool( THEPL, "play-and-exit" );
1171 bool MainInputManager::hasEmptyPlaylist()
1173 playlist_Lock( THEPL );
1174 bool b_empty = playlist_IsEmpty( THEPL );
1175 playlist_Unlock( THEPL );
1179 /****************************
1180 * Static callbacks for MIM *
1181 ****************************/
1182 static int PLItemChanged( vlc_object_t *p_this, const char *psz_var,
1183 vlc_value_t oldval, vlc_value_t, void *param )
1185 VLC_UNUSED( p_this ); VLC_UNUSED( psz_var ); VLC_UNUSED( oldval );
1187 MainInputManager *mim = (MainInputManager*)param;
1189 IMEvent *event = new IMEvent( ItemChanged_Type );
1190 QApplication::postEvent( mim, event );
1194 static int LeafToParent( vlc_object_t *p_this, const char *psz_var,
1195 vlc_value_t oldval, vlc_value_t newval, void *param )
1197 VLC_UNUSED( p_this ); VLC_UNUSED( psz_var ); VLC_UNUSED( oldval );
1198 MainInputManager *mim = (MainInputManager*)param;
1200 PLEvent *event = new PLEvent( LeafToParent_Type, newval.i_int );
1202 QApplication::postEvent( mim, event );
1206 static int VolumeChanged( vlc_object_t *p_this, const char *psz_var,
1207 vlc_value_t oldval, vlc_value_t newval, void *param )
1209 VLC_UNUSED( p_this ); VLC_UNUSED( psz_var ); VLC_UNUSED( oldval ); VLC_UNUSED( newval );
1211 MainInputManager *mim = (MainInputManager*)param;
1213 IMEvent *event = new IMEvent( VolumeChanged_Type );
1214 QApplication::postEvent( mim, event );
1218 static int SoundMuteChanged( vlc_object_t *p_this, const char *psz_var,
1219 vlc_value_t oldval, vlc_value_t newval, void *param )
1221 VLC_UNUSED( p_this ); VLC_UNUSED( psz_var ); VLC_UNUSED( oldval ); VLC_UNUSED( newval );
1223 MainInputManager *mim = (MainInputManager*)param;
1225 IMEvent *event = new IMEvent( SoundMuteChanged_Type );
1226 QApplication::postEvent( mim, event );
1230 static int PLItemAppended
1231 ( vlc_object_t * obj, const char *var, vlc_value_t old, vlc_value_t cur, void *data )
1233 VLC_UNUSED( obj ); VLC_UNUSED( var ); VLC_UNUSED( old );
1234 MainInputManager *mim = static_cast<MainInputManager*>(data);
1235 playlist_add_t *p_add = static_cast<playlist_add_t*>( cur.p_address );
1237 PLEvent *event = new PLEvent( PLItemAppended_Type, p_add->i_item, p_add->i_node );
1238 QApplication::postEvent( mim, event );
1239 event = new PLEvent( PLEmpty_Type, p_add->i_item, 0 );
1240 QApplication::postEvent( mim, event );
1243 static int PLItemRemoved
1244 ( vlc_object_t * obj, const char *var, vlc_value_t old, vlc_value_t cur, void *data )
1246 VLC_UNUSED( var ); VLC_UNUSED( old );
1248 playlist_t *pl = (playlist_t *) obj;
1249 MainInputManager *mim = static_cast<MainInputManager*>(data);
1251 PLEvent *event = new PLEvent( PLItemRemoved_Type, cur.i_int, 0 );
1252 QApplication::postEvent( mim, event );
1253 // can't use playlist_IsEmpty( ) as it isn't true yet
1254 if ( pl->items.i_size == 1 ) // lock is held
1256 event = new PLEvent( PLEmpty_Type, -1, 0 );
1257 QApplication::postEvent( mim, event );