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
32 #include "input_manager.hpp"
35 #include <vlc_strings.h>
38 #include <QApplication>
42 static int ItemChanged( vlc_object_t *, const char *,
43 vlc_value_t, vlc_value_t, void * );
44 static int LeafToParent( vlc_object_t *, const char *,
45 vlc_value_t, vlc_value_t, void * );
46 static int PLItemChanged( vlc_object_t *, const char *,
47 vlc_value_t, vlc_value_t, void * );
48 static int PLItemAppended( vlc_object_t *, const char *,
49 vlc_value_t, vlc_value_t, void * );
50 static int PLItemRemoved( vlc_object_t *, const char *,
51 vlc_value_t, vlc_value_t, void * );
52 static int VolumeChanged( vlc_object_t *, const char *,
53 vlc_value_t, vlc_value_t, void * );
54 static int SoundMuteChanged( vlc_object_t *, const char *,
55 vlc_value_t, vlc_value_t, void * );
57 static int RandomChanged( vlc_object_t *, const char *,
58 vlc_value_t, vlc_value_t, void * );
59 static int LoopChanged( vlc_object_t *, const char *,
60 vlc_value_t, vlc_value_t, void * );
61 static int RepeatChanged( vlc_object_t *, const char *,
62 vlc_value_t, vlc_value_t, void * );
65 static int InputEvent( vlc_object_t *, const char *,
66 vlc_value_t, vlc_value_t, void * );
67 static int VbiEvent( vlc_object_t *, const char *,
68 vlc_value_t, vlc_value_t, void * );
71 /**********************************************************************
72 * InputManager implementation
73 **********************************************************************
74 * The Input Manager can be the main one around the playlist
75 * But can also be used for VLM dialog or similar
76 **********************************************************************/
78 InputManager::InputManager( QObject *parent, intf_thread_t *_p_intf) :
79 QObject( parent ), p_intf( _p_intf )
81 i_old_playing_status = END_S;
91 f_cache = -1.; /* impossible initial value, different from all */
94 InputManager::~InputManager()
99 /* Define the Input used.
100 Add the callbacks on input
101 p_input is held once here */
102 void InputManager::setInput( input_thread_t *_p_input )
106 if( p_input && !( p_input->b_dead || !vlc_object_alive (p_input) ) )
108 msg_Dbg( p_intf, "IM: Setting an input" );
109 vlc_object_hold( p_input );
118 p_item = input_GetItem( p_input );
119 emit rateChanged( var_GetFloat( p_input, "rate" ) );
125 assert( !p_input_vbi );
126 emit rateChanged( var_InheritFloat( p_intf, "rate" ) );
130 /* delete Input if it ever existed.
131 Delete the callbacls on input
132 p_input is released once here */
133 void InputManager::delInput()
135 if( !p_input ) return;
136 msg_Dbg( p_intf, "IM: Deleting the input" );
139 i_old_playing_status = END_S;
150 vlc_object_release( p_input_vbi );
154 vlc_object_release( p_input );
157 emit positionUpdated( -1.0, 0 ,0 );
158 emit rateChanged( var_InheritFloat( p_intf, "rate" ) );
159 emit nameChanged( "" );
160 emit chapterChanged( 0 );
161 emit titleChanged( 0 );
162 emit playingStatusChanged( END_S );
164 emit teletextPossible( false );
165 emit AtoBchanged( false, false );
166 emit voutChanged( false );
167 emit voutListChanged( NULL, 0 );
169 /* Reset all InfoPanels but stats */
170 emit artChanged( NULL );
171 emit infoChanged( NULL );
172 emit currentMetaChanged( (input_item_t *)NULL );
174 emit encryptionChanged( false );
175 emit recordingStateChanged( false );
177 emit cachingChanged( 1 );
180 /* Convert the event from the callbacks in actions */
181 void InputManager::customEvent( QEvent *event )
183 int i_type = event->type();
184 IMEvent *ple = static_cast<IMEvent *>(event);
186 if( i_type == ItemChanged_Type )
187 UpdateMeta( ple->p_item );
195 case PositionUpdate_Type:
198 case StatisticsUpdate_Type:
201 case ItemChanged_Type:
202 /* Ignore ItemChanged_Type event that does not apply to our input */
203 if( p_item == ple->p_item )
208 /* Update duration of file */
211 case ItemStateChanged_Type:
212 // TODO: Fusion with above state
215 // UpdateNavigation(); This shouldn't be useful now
216 // UpdateTeletext(); Same
218 case NameChanged_Type:
221 case MetaChanged_Type:
223 UpdateName(); /* Needed for NowPlaying */
224 UpdateArt(); /* Art is part of meta in the core */
226 case InfoChanged_Type:
229 case ItemTitleChanged_Type:
231 UpdateName(); /* Display the name of the Chapter, if exists */
233 case ItemRateChanged_Type:
236 case ItemEsChanged_Type:
238 // We don't do anything ES related. Why ?
240 case ItemTeletextChanged_Type:
243 case InterfaceVoutUpdate_Type:
246 case SynchroChanged_Type:
247 emit synchroChanged();
249 case CachingEvent_Type:
252 case BookmarksChanged_Type:
253 emit bookmarksChanged();
255 case InterfaceAoutUpdate_Type:
258 case RecordingEvent_Type:
261 case ProgramChanged_Type:
262 UpdateProgramEvent();
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( ItemChanged_Type, 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( ItemStateChanged_Type );
312 case INPUT_EVENT_RATE:
313 event = new IMEvent( ItemRateChanged_Type );
315 case INPUT_EVENT_POSITION:
316 //case INPUT_EVENT_LENGTH:
317 event = new IMEvent( PositionUpdate_Type );
320 case INPUT_EVENT_TITLE:
321 case INPUT_EVENT_CHAPTER:
322 event = new IMEvent( ItemTitleChanged_Type );
326 event = new IMEvent( ItemEsChanged_Type );
328 case INPUT_EVENT_TELETEXT:
329 event = new IMEvent( ItemTeletextChanged_Type );
332 case INPUT_EVENT_STATISTICS:
333 event = new IMEvent( StatisticsUpdate_Type );
336 case INPUT_EVENT_VOUT:
337 event = new IMEvent( InterfaceVoutUpdate_Type );
339 case INPUT_EVENT_AOUT:
340 event = new IMEvent( InterfaceAoutUpdate_Type );
343 case INPUT_EVENT_ITEM_META: /* Codec MetaData + Art */
344 event = new IMEvent( MetaChanged_Type );
346 case INPUT_EVENT_ITEM_INFO: /* Codec Info */
347 event = new IMEvent( InfoChanged_Type );
349 case INPUT_EVENT_ITEM_NAME:
350 event = new IMEvent( NameChanged_Type );
353 case INPUT_EVENT_AUDIO_DELAY:
354 case INPUT_EVENT_SUBTITLE_DELAY:
355 event = new IMEvent( SynchroChanged_Type );
358 case INPUT_EVENT_CACHE:
359 event = new IMEvent( CachingEvent_Type );
362 case INPUT_EVENT_BOOKMARK:
363 event = new IMEvent( BookmarksChanged_Type );
366 case INPUT_EVENT_RECORD:
367 event = new IMEvent( RecordingEvent_Type );
370 case INPUT_EVENT_PROGRAM:
371 /* This is for PID changes */
372 event = new IMEvent( ProgramChanged_Type );
375 case INPUT_EVENT_ITEM_EPG:
376 /* EPG data changed */
377 event = new IMEvent( EPGEvent_Type );
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( ItemTeletextChanged_Type );
400 QApplication::postEvent( im, event );
404 void InputManager::UpdatePosition()
406 /* Update position */
410 i_length = var_GetTime( p_input , "length" ) / 1000000;
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 emit titleChanged( true );
428 msg_Dbg( p_intf, "Title %"PRId64, val.i_int );
429 /* p_input != NULL since val.i_int != 0 */
430 var_Change( p_input, "chapter", VLC_VAR_CHOICESCOUNT, &val2, NULL );
431 emit chapterChanged( (val2.i_int > 1) || ( val2.i_int > 0 && val.i_int > 1 ) );
432 msg_Dbg( p_intf, "Chapter: %"PRId64, val2.i_int );
435 emit titleChanged( false );
438 void InputManager::UpdateStatus()
440 /* Update playing status */
441 int state = var_GetInteger( p_input, "state" );
442 if( i_old_playing_status != state )
444 i_old_playing_status = state;
445 emit playingStatusChanged( state );
449 void InputManager::UpdateRate()
452 float f_new_rate = var_GetFloat( p_input, "rate" );
453 if( f_new_rate != f_rate )
457 emit rateChanged( f_rate );
461 void InputManager::UpdateName()
463 /* Update text, name and nowplaying */
466 /* Try to get the nowplaying */
467 char *format = var_InheritString( p_intf, "input-title-format" );
468 char *formated = str_format_meta( p_input, format );
470 name = qfu(formated);
473 /* If we have Nothing */
476 char *uri = input_item_GetURI( input_GetItem( p_input ) );
477 char *file = uri ? strrchr( uri, '/' ) : NULL;
480 decode_URI( ++file );
488 name = name.trimmed();
490 if( oldName != name )
492 emit nameChanged( name );
497 int InputManager::playingStatus()
499 return i_old_playing_status;
502 bool InputManager::hasAudio()
507 var_Change( p_input, "audio-es", VLC_VAR_CHOICESCOUNT, &val, NULL );
508 return val.i_int > 0;
513 bool InputManager::hasVisualisation()
518 aout_instance_t *aout = input_GetAout( p_input );
522 char *visual = var_InheritString( aout, "visual" );
523 vlc_object_release( aout );
532 void InputManager::UpdateTeletext()
536 const bool b_enabled = var_CountChoices( p_input, "teletext-es" ) > 0;
537 const int i_teletext_es = var_GetInteger( p_input, "teletext-es" );
539 /* Teletext is possible. Show the buttons */
540 emit teletextPossible( b_enabled );
542 /* If Teletext is selected */
543 if( b_enabled && i_teletext_es >= 0 )
545 /* Then, find the current page */
547 bool b_transparent = false;
551 var_DelCallback( p_input_vbi, "vbi-page", VbiEvent, this );
552 vlc_object_release( p_input_vbi );
555 if( input_GetEsObjects( p_input, i_teletext_es, &p_input_vbi, NULL, NULL ) )
560 /* This callback is not remove explicitly, but interfaces
561 * are guaranted to outlive input */
562 var_AddCallback( p_input_vbi, "vbi-page", VbiEvent, this );
564 i_page = var_GetInteger( p_input_vbi, "vbi-page" );
565 b_transparent = !var_GetBool( p_input_vbi, "vbi-opaque" );
567 emit newTelexPageSet( i_page );
568 emit teletextTransparencyActivated( b_transparent );
571 emit teletextActivated( b_enabled && i_teletext_es >= 0 );
575 emit teletextActivated( false );
576 emit teletextPossible( false );
580 void InputManager::UpdateEPG()
588 void InputManager::UpdateVout()
592 /* Get current vout lists from input */
594 vout_thread_t **pp_vout;
595 if( input_Control( p_input, INPUT_GET_VOUTS, &pp_vout, &i_vout ) )
602 emit voutListChanged( pp_vout, i_vout );
605 bool b_old_video = b_video;
606 b_video = i_vout > 0;
607 if( !!b_old_video != !!b_video )
608 emit voutChanged( b_video );
610 /* Release the vout list */
611 for( size_t i = 0; i < i_vout; i++ )
612 vlc_object_release( (vlc_object_t*)pp_vout[i] );
616 void InputManager::UpdateAout()
623 void InputManager::UpdateCaching()
625 if(!hasInput()) return;
627 float f_newCache = var_GetFloat ( p_input, "cache" );
628 if( f_newCache != f_cache )
630 f_cache = f_newCache;
632 emit cachingChanged( f_cache );
636 void InputManager::requestArtUpdate()
640 playlist_AskForArtEnqueue( pl_Get(p_intf), input_GetItem( p_input ) );
644 /* No input will signal the cover art to update,
645 * let's do it ourself */
650 const QString InputManager::decodeArtURL( input_item_t *p_item )
654 char *psz_art = input_item_GetArtURL( p_item );
657 char *psz = make_path( psz_art );
663 /* Taglib seems to define a attachment://, It won't work yet */
664 url = url.replace( "attachment://", "" );
667 QString path = qfu( psz_art ? psz_art : "" );
672 void InputManager::UpdateArt()
677 url = decodeArtURL( input_GetItem( p_input ) );
679 /* the art hasn't changed, no need to update */
683 /* Update Art meta */
685 emit artChanged( artUrl );
688 inline void InputManager::UpdateStats()
690 emit statisticsUpdated( input_GetItem( p_input ) );
693 inline void InputManager::UpdateMeta( input_item_t *p_item )
695 emit metaChanged( p_item );
698 inline void InputManager::UpdateMeta()
700 emit currentMetaChanged( input_GetItem( p_input ) );
703 inline void InputManager::UpdateInfo()
705 emit infoChanged( input_GetItem( p_input ) );
708 void InputManager::UpdateRecord()
712 emit recordingStateChanged( var_GetBool( p_input, "record" ) );
716 void InputManager::UpdateProgramEvent()
720 bool b_scrambled = var_GetBool( p_input, "program-scrambled" );
721 emit encryptionChanged( b_scrambled );
725 /* User update of the slider */
726 void InputManager::sliderUpdate( float new_pos )
729 var_SetFloat( p_input, "position", new_pos );
730 emit seekRequested( new_pos );
733 /* User togglePlayPause */
734 void InputManager::togglePlayPause()
738 int state = var_GetInteger( p_input, "state" );
739 state = ( state != PLAYING_S ) ? PLAYING_S : PAUSE_S;
740 var_SetInteger( p_input, "state", state );
744 void InputManager::sectionPrev()
748 int i_type = var_Type( p_input, "next-chapter" );
749 var_TriggerCallback( p_input, (i_type & VLC_VAR_TYPE) != 0 ?
750 "prev-chapter":"prev-title" );
754 void InputManager::sectionNext()
758 int i_type = var_Type( p_input, "next-chapter" );
759 var_TriggerCallback( p_input, (i_type & VLC_VAR_TYPE) != 0 ?
760 "next-chapter":"next-title" );
764 void InputManager::sectionMenu()
768 vlc_value_t val, text;
770 if( var_Change( p_input, "title 0", VLC_VAR_GETLIST, &val, &text ) < 0 )
773 /* XXX is it "Root" or "Title" we want here ?" (set 0 by default) */
775 for( int i = 0; i < val.p_list->i_count; i++ )
777 if( !strcmp( text.p_list->p_values[i].psz_string, "Title" ) )
780 var_FreeList( &val, &text );
782 var_SetInteger( p_input, "title 0", root );
790 /* Set a new Teletext Page */
791 void InputManager::telexSetPage( int page )
793 if( hasInput() && p_input_vbi )
795 const int i_teletext_es = var_GetInteger( p_input, "teletext-es" );
797 if( i_teletext_es >= 0 )
799 var_SetInteger( p_input_vbi, "vbi-page", page );
800 emit newTelexPageSet( page );
805 /* Set the transparency on teletext */
806 void InputManager::telexSetTransparency( bool b_transparentTelextext )
808 if( hasInput() && p_input_vbi )
810 var_SetBool( p_input_vbi, "vbi-opaque", !b_transparentTelextext );
811 emit teletextTransparencyActivated( b_transparentTelextext );
815 void InputManager::activateTeletext( bool b_enable )
819 if( hasInput() && !var_Change( p_input, "teletext-es", VLC_VAR_GETLIST, &list, &text ) )
821 if( list.p_list->i_count > 0 )
823 /* Prefer the page 100 if it is present */
825 for( i = 0; i < text.p_list->i_count; i++ )
827 /* The description is the page number as a string */
828 const char *psz_page = text.p_list->p_values[i].psz_string;
829 if( psz_page && !strcmp( psz_page, "100" ) )
832 if( i >= list.p_list->i_count )
834 var_SetInteger( p_input, "spu-es", b_enable ? list.p_list->p_values[i].i_int : -1 );
836 var_FreeList( &list, &text );
840 void InputManager::reverse()
844 float f_rate = var_GetFloat( p_input, "rate" );
845 var_SetFloat( p_input, "rate", -f_rate );
849 void InputManager::slower()
851 var_TriggerCallback( THEPL, "rate-slower" );
854 void InputManager::faster()
856 var_TriggerCallback( THEPL, "rate-faster" );
859 void InputManager::littlefaster()
861 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_RATE_FASTER_FINE );
864 void InputManager::littleslower()
866 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_RATE_SLOWER_FINE );
869 void InputManager::normalRate()
871 var_SetFloat( THEPL, "rate", 1. );
874 void InputManager::setRate( int new_rate )
876 var_SetFloat( THEPL, "rate",
877 (float)INPUT_RATE_DEFAULT / (float)new_rate );
880 void InputManager::jumpFwd()
882 int i_interval = var_InheritInteger( p_input, "short-jump-size" );
885 mtime_t val = (mtime_t)(i_interval) * 1000000L;
886 var_SetTime( p_input, "time-offset", val );
890 void InputManager::jumpBwd()
892 int i_interval = var_InheritInteger( p_input, "short-jump-size" );
895 mtime_t val = -1 *(mtime_t)(i_interval) * 1000000L;
896 var_SetTime( p_input, "time-offset", val );
900 void InputManager::setAtoB()
904 timeA = var_GetTime( THEMIM->getInput(), "time" );
908 timeB = var_GetTime( THEMIM->getInput(), "time" );
909 var_SetTime( THEMIM->getInput(), "time" , timeA );
910 CONNECT( this, positionUpdated( float, int64_t, int ),
911 this, AtoBLoop( float, int64_t, int ) );
917 disconnect( this, SIGNAL( positionUpdated( float, int64_t, int ) ),
918 this, SLOT( AtoBLoop( float, int64_t, int ) ) );
920 emit AtoBchanged( (timeA != 0 ), (timeB != 0 ) );
923 /* Function called regularly when in an AtoB loop */
924 void InputManager::AtoBLoop( float, int64_t i_time, int )
928 if( i_time >= timeB || i_time < timeA )
929 var_SetTime( THEMIM->getInput(), "time" , timeA );
933 /**********************************************************************
934 * MainInputManager implementation. Wrap an input manager and
935 * take care of updating the main playlist input.
936 * Used in the main playlist Dialog
937 **********************************************************************/
939 MainInputManager::MainInputManager( intf_thread_t *_p_intf )
940 : QObject(NULL), p_intf( _p_intf )
943 im = new InputManager( this, p_intf );
945 var_AddCallback( THEPL, "item-change", ItemChanged, im );
946 var_AddCallback( THEPL, "item-current", PLItemChanged, this );
947 var_AddCallback( THEPL, "activity", PLItemChanged, this );
948 var_AddCallback( THEPL, "leaf-to-parent", LeafToParent, this );
949 var_AddCallback( THEPL, "playlist-item-append", PLItemAppended, this );
950 var_AddCallback( THEPL, "playlist-item-deleted", PLItemRemoved, this );
951 var_AddCallback( THEPL, "random", RandomChanged, this );
952 var_AddCallback( THEPL, "repeat", RepeatChanged, this );
953 var_AddCallback( THEPL, "loop", LoopChanged, this );
955 var_AddCallback( THEPL, "volume", VolumeChanged, this );
956 var_AddCallback( THEPL, "mute", SoundMuteChanged, this );
958 /* Warn our embedded IM about input changes */
959 DCONNECT( this, inputChanged( input_thread_t * ),
960 im, setInput( input_thread_t * ) );
964 MainInputManager::~MainInputManager()
968 emit inputChanged( NULL );
969 var_DelCallback( p_input, "state", PLItemChanged, this );
970 vlc_object_release( p_input );
973 var_DelCallback( THEPL, "volume", VolumeChanged, this );
974 var_DelCallback( THEPL, "mute", SoundMuteChanged, this );
976 var_DelCallback( THEPL, "activity", PLItemChanged, this );
977 var_DelCallback( THEPL, "item-change", ItemChanged, im );
978 var_DelCallback( THEPL, "leaf-to-parent", LeafToParent, this );
980 var_DelCallback( THEPL, "item-current", PLItemChanged, this );
981 var_DelCallback( THEPL, "playlist-item-append", PLItemAppended, this );
982 var_DelCallback( THEPL, "playlist-item-deleted", PLItemRemoved, this );
983 var_DelCallback( THEPL, "random", RandomChanged, this );
984 var_DelCallback( THEPL, "repeat", RepeatChanged, this );
985 var_DelCallback( THEPL, "loop", LoopChanged, this );
989 vout_thread_t* MainInputManager::getVout()
991 return p_input ? input_GetVout( p_input ) : NULL;
994 aout_instance_t * MainInputManager::getAout()
996 return p_input ? input_GetAout( p_input ) : NULL;
999 void MainInputManager::customEvent( QEvent *event )
1001 int type = event->type();
1005 // msg_Dbg( p_intf, "New MainIM Event of type: %i", type );
1008 case VolumeChanged_Type:
1009 emit volumeChanged();
1011 case SoundMuteChanged_Type:
1012 emit soundMuteChanged();
1014 case PLItemAppended_Type:
1015 plEv = static_cast<PLEvent*>( event );
1016 emit playlistItemAppended( plEv->i_item, plEv->i_parent );
1018 case PLItemRemoved_Type:
1019 plEv = static_cast<PLEvent*>( event );
1020 emit playlistItemRemoved( plEv->i_item );
1022 case RandomChanged_Type:
1023 emit randomChanged( var_GetBool( THEPL, "random" ) );
1025 case LoopChanged_Type:
1026 case RepeatChanged_Type:
1029 case LeafToParent_Type:
1030 plEv = static_cast<PLEvent*>( event );
1031 emit leafBecameParent( plEv->i_item );
1034 if( type != ItemChanged_Type ) return;
1037 /* Should be PLItemChanged Event */
1038 if( !p_intf->p_sys->b_isDialogProvider )
1040 if( p_input && ( p_input->b_dead || !vlc_object_alive (p_input) ) )
1042 emit inputChanged( p_input );
1043 var_DelCallback( p_input, "state", PLItemChanged, this );
1044 vlc_object_release( p_input );
1051 p_input = playlist_CurrentInput(THEPL);
1054 var_AddCallback( p_input, "state", PLItemChanged, this );
1055 emit inputChanged( p_input );
1061 /* remove previous stored p_input */
1064 vlc_object_release( p_input );
1067 /* we are working as a dialogs provider */
1068 p_input = playlist_CurrentInput( pl_Get(p_intf) );
1071 emit inputChanged( p_input );
1076 /* Playlist Control functions */
1077 void MainInputManager::stop()
1079 playlist_Stop( THEPL );
1082 void MainInputManager::next()
1084 playlist_Next( THEPL );
1087 void MainInputManager::prev()
1089 playlist_Prev( THEPL );
1092 void MainInputManager::prevOrReset()
1094 if( !p_input || var_GetTime( p_input , "time") < 10000 )
1095 playlist_Prev( THEPL );
1097 getIM()->sliderUpdate( 0.0 );
1100 void MainInputManager::togglePlayPause()
1102 /* No input, play */
1104 playlist_Play( THEPL );
1106 getIM()->togglePlayPause();
1109 void MainInputManager::play()
1111 /* No input, play */
1113 playlist_Play( THEPL );
1116 if( PLAYING_S != var_GetInteger( p_input, "state" ) )
1118 getIM()->togglePlayPause();
1123 void MainInputManager::pause()
1125 if(p_input && PLAYING_S == var_GetInteger( p_input, "state" ) )
1127 getIM()->togglePlayPause();
1131 void MainInputManager::toggleRandom()
1133 var_ToggleBool( THEPL, "random" );
1136 void MainInputManager::notifyRepeatLoop()
1138 int i_value = var_GetBool( THEPL, "loop" ) * REPEAT_ALL
1139 + var_GetBool( THEPL, "repeat" ) * REPEAT_ONE;
1141 emit repeatLoopChanged( i_value );
1144 void MainInputManager::loopRepeatLoopStatus()
1146 /* Toggle Normal -> Loop -> Repeat -> Normal ... */
1147 if( var_GetBool( THEPL, "repeat" ) )
1148 var_SetBool( THEPL, "repeat", false );
1149 else if( var_GetBool( THEPL, "loop" ) )
1151 var_SetBool( THEPL, "loop", false );
1152 var_SetBool( THEPL, "repeat", true );
1155 var_SetBool( THEPL, "loop", true );
1158 void MainInputManager::activatePlayQuit( bool b_exit )
1160 var_SetBool( THEPL, "play-and-exit", b_exit );
1163 bool MainInputManager::getPlayExitState()
1165 return var_GetBool( THEPL, "play-and-exit" );
1168 /****************************
1169 * Static callbacks for MIM *
1170 ****************************/
1171 static int PLItemChanged( vlc_object_t *p_this, const char *psz_var,
1172 vlc_value_t oldval, vlc_value_t, void *param )
1174 VLC_UNUSED( p_this ); VLC_UNUSED( psz_var ); VLC_UNUSED( oldval );
1176 MainInputManager *mim = (MainInputManager*)param;
1178 IMEvent *event = new IMEvent( ItemChanged_Type );
1179 QApplication::postEvent( mim, event );
1183 static int LeafToParent( vlc_object_t *p_this, const char *psz_var,
1184 vlc_value_t oldval, vlc_value_t newval, void *param )
1186 VLC_UNUSED( p_this ); VLC_UNUSED( psz_var ); VLC_UNUSED( oldval );
1187 MainInputManager *mim = (MainInputManager*)param;
1189 PLEvent *event = new PLEvent( LeafToParent_Type, newval.i_int );
1191 QApplication::postEvent( mim, event );
1195 static int VolumeChanged( vlc_object_t *p_this, const char *psz_var,
1196 vlc_value_t oldval, vlc_value_t newval, void *param )
1198 VLC_UNUSED( p_this ); VLC_UNUSED( psz_var ); VLC_UNUSED( oldval ); VLC_UNUSED( newval );
1200 MainInputManager *mim = (MainInputManager*)param;
1202 IMEvent *event = new IMEvent( VolumeChanged_Type );
1203 QApplication::postEvent( mim, event );
1207 static int SoundMuteChanged( vlc_object_t *p_this, const char *psz_var,
1208 vlc_value_t oldval, vlc_value_t newval, void *param )
1210 VLC_UNUSED( p_this ); VLC_UNUSED( psz_var ); VLC_UNUSED( oldval ); VLC_UNUSED( newval );
1212 MainInputManager *mim = (MainInputManager*)param;
1214 IMEvent *event = new IMEvent( SoundMuteChanged_Type );
1215 QApplication::postEvent( mim, event );
1219 static int PLItemAppended
1220 ( vlc_object_t * obj, const char *var, vlc_value_t old, vlc_value_t cur, void *data )
1222 VLC_UNUSED( obj ); VLC_UNUSED( var ); VLC_UNUSED( old );
1224 MainInputManager *mim = static_cast<MainInputManager*>(data);
1225 playlist_add_t *p_add = static_cast<playlist_add_t*>( cur.p_address );
1227 PLEvent *event = new PLEvent( PLItemAppended_Type, p_add->i_item, p_add->i_node );
1228 QApplication::postEvent( mim, event );
1231 static int PLItemRemoved
1232 ( vlc_object_t * obj, const char *var, vlc_value_t old, vlc_value_t cur, void *data )
1234 VLC_UNUSED( obj ); VLC_UNUSED( var ); VLC_UNUSED( old );
1236 MainInputManager *mim = static_cast<MainInputManager*>(data);
1238 PLEvent *event = new PLEvent( PLItemRemoved_Type, cur.i_int, 0 );
1239 QApplication::postEvent( mim, event );
1243 static int RandomChanged
1244 ( vlc_object_t * obj, const char *var, vlc_value_t old, vlc_value_t cur, void *data )
1246 VLC_UNUSED( obj ); VLC_UNUSED( var ); VLC_UNUSED( old ); VLC_UNUSED( cur );
1248 MainInputManager *mim = static_cast<MainInputManager*>(data);
1250 IMEvent *event = new IMEvent( RandomChanged_Type );
1251 QApplication::postEvent( mim, event );
1255 /* Probably could be merged with next callback */
1256 static int LoopChanged
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 ); VLC_UNUSED( cur );
1261 MainInputManager *mim = static_cast<MainInputManager*>(data);
1263 IMEvent *event = new IMEvent( LoopChanged_Type );
1264 QApplication::postEvent( mim, event );
1268 static int RepeatChanged
1269 ( vlc_object_t * obj, const char *var, vlc_value_t old, vlc_value_t cur, void *data )
1271 VLC_UNUSED( obj ); VLC_UNUSED( var ); VLC_UNUSED( old ); VLC_UNUSED( cur );
1273 MainInputManager *mim = static_cast<MainInputManager*>(data);
1275 IMEvent *event = new IMEvent( RepeatChanged_Type );
1276 QApplication::postEvent( mim, event );