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>
37 #include <QApplication>
41 static int ItemChanged( vlc_object_t
*, const char *,
42 vlc_value_t
, vlc_value_t
, void * );
43 static int LeafToParent( vlc_object_t
*, const char *,
44 vlc_value_t
, vlc_value_t
, void * );
45 static int PLItemChanged( vlc_object_t
*, const char *,
46 vlc_value_t
, vlc_value_t
, void * );
47 static int PLItemAppended( vlc_object_t
*, const char *,
48 vlc_value_t
, vlc_value_t
, void * );
49 static int PLItemRemoved( vlc_object_t
*, const char *,
50 vlc_value_t
, vlc_value_t
, void * );
51 static int VolumeChanged( vlc_object_t
*, const char *,
52 vlc_value_t
, vlc_value_t
, void * );
53 static int SoundMuteChanged( vlc_object_t
*, const char *,
54 vlc_value_t
, vlc_value_t
, void * );
56 static int RandomChanged( vlc_object_t
*, const char *,
57 vlc_value_t
, vlc_value_t
, void * );
58 static int LoopChanged( vlc_object_t
*, const char *,
59 vlc_value_t
, vlc_value_t
, void * );
60 static int RepeatChanged( vlc_object_t
*, const char *,
61 vlc_value_t
, vlc_value_t
, void * );
64 static int InputEvent( vlc_object_t
*, const char *,
65 vlc_value_t
, vlc_value_t
, void * );
66 static int VbiEvent( vlc_object_t
*, const char *,
67 vlc_value_t
, vlc_value_t
, void * );
70 /**********************************************************************
71 * InputManager implementation
72 **********************************************************************
73 * The Input Manager can be the main one around the playlist
74 * But can also be used for VLM dialog or similar
75 **********************************************************************/
77 InputManager::InputManager( QObject
*parent
, intf_thread_t
*_p_intf
) :
78 QObject( parent
), p_intf( _p_intf
)
80 i_old_playing_status
= END_S
;
90 f_cache
= -1.; /* impossible initial value, different from all */
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
== ItemChanged_Type
)
186 UpdateMeta( ple
->p_item
);
194 case PositionUpdate_Type
:
197 case StatisticsUpdate_Type
:
200 case ItemChanged_Type
:
201 /* Ignore ItemChanged_Type event that does not apply to our input */
202 if( p_item
== ple
->p_item
)
207 /* Update duration of file */
210 case ItemStateChanged_Type
:
211 // TODO: Fusion with above state
214 // UpdateNavigation(); This shouldn't be useful now
215 // UpdateTeletext(); Same
217 case NameChanged_Type
:
220 case MetaChanged_Type
:
222 UpdateName(); /* Needed for NowPlaying */
223 UpdateArt(); /* Art is part of meta in the core */
225 case InfoChanged_Type
:
228 case ItemTitleChanged_Type
:
230 UpdateName(); /* Display the name of the Chapter, if exists */
232 case ItemRateChanged_Type
:
235 case ItemEsChanged_Type
:
237 // We don't do anything ES related. Why ?
239 case ItemTeletextChanged_Type
:
242 case InterfaceVoutUpdate_Type
:
245 case SynchroChanged_Type
:
246 emit
synchroChanged();
248 case CachingEvent_Type
:
251 case BookmarksChanged_Type
:
252 emit
bookmarksChanged();
254 case InterfaceAoutUpdate_Type
:
257 case RecordingEvent_Type
:
260 case ProgramChanged_Type
:
261 UpdateProgramEvent();
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 );
278 /* Delete the callbacks on Input. Self explanatory */
279 inline void InputManager::delCallbacks()
281 var_DelCallback( p_input
, "intf-event", InputEvent
, this );
284 /* Static callbacks for IM */
285 static int ItemChanged( vlc_object_t
*p_this
, const char *psz_var
,
286 vlc_value_t oldval
, vlc_value_t newval
, void *param
)
288 VLC_UNUSED( p_this
); VLC_UNUSED( psz_var
); VLC_UNUSED( oldval
);
290 InputManager
*im
= (InputManager
*)param
;
291 input_item_t
*p_item
= static_cast<input_item_t
*>(newval
.p_address
);
293 IMEvent
*event
= new IMEvent( ItemChanged_Type
, p_item
);
294 QApplication::postEvent( im
, event
);
298 static int InputEvent( vlc_object_t
*p_this
, const char *,
299 vlc_value_t
, vlc_value_t newval
, void *param
)
301 VLC_UNUSED( p_this
);
303 InputManager
*im
= (InputManager
*)param
;
306 switch( newval
.i_int
)
308 case INPUT_EVENT_STATE
:
309 event
= new IMEvent( ItemStateChanged_Type
);
311 case INPUT_EVENT_RATE
:
312 event
= new IMEvent( ItemRateChanged_Type
);
314 case INPUT_EVENT_POSITION
:
315 //case INPUT_EVENT_LENGTH:
316 event
= new IMEvent( PositionUpdate_Type
);
319 case INPUT_EVENT_TITLE
:
320 case INPUT_EVENT_CHAPTER
:
321 event
= new IMEvent( ItemTitleChanged_Type
);
325 event
= new IMEvent( ItemEsChanged_Type
);
327 case INPUT_EVENT_TELETEXT
:
328 event
= new IMEvent( ItemTeletextChanged_Type
);
331 case INPUT_EVENT_STATISTICS
:
332 event
= new IMEvent( StatisticsUpdate_Type
);
335 case INPUT_EVENT_VOUT
:
336 event
= new IMEvent( InterfaceVoutUpdate_Type
);
338 case INPUT_EVENT_AOUT
:
339 event
= new IMEvent( InterfaceAoutUpdate_Type
);
342 case INPUT_EVENT_ITEM_META
: /* Codec MetaData + Art */
343 event
= new IMEvent( MetaChanged_Type
);
345 case INPUT_EVENT_ITEM_INFO
: /* Codec Info */
346 event
= new IMEvent( InfoChanged_Type
);
348 case INPUT_EVENT_ITEM_NAME
:
349 event
= new IMEvent( NameChanged_Type
);
352 case INPUT_EVENT_AUDIO_DELAY
:
353 case INPUT_EVENT_SUBTITLE_DELAY
:
354 event
= new IMEvent( SynchroChanged_Type
);
357 case INPUT_EVENT_CACHE
:
358 event
= new IMEvent( CachingEvent_Type
);
361 case INPUT_EVENT_BOOKMARK
:
362 event
= new IMEvent( BookmarksChanged_Type
);
365 case INPUT_EVENT_RECORD
:
366 event
= new IMEvent( RecordingEvent_Type
);
369 case INPUT_EVENT_PROGRAM
:
370 /* This is for PID changes */
371 event
= new IMEvent( ProgramChanged_Type
);
374 case INPUT_EVENT_ITEM_EPG
:
375 /* EPG data changed */
376 event
= new IMEvent( EPGEvent_Type
);
379 case INPUT_EVENT_SIGNAL
:
380 /* This is for capture-card signals */
381 /* event = new IMEvent( SignalChanged_Type );
389 QApplication::postEvent( im
, event
);
393 static int VbiEvent( vlc_object_t
*, const char *,
394 vlc_value_t
, vlc_value_t
, void *param
)
396 InputManager
*im
= (InputManager
*)param
;
397 IMEvent
*event
= new IMEvent( ItemTeletextChanged_Type
);
399 QApplication::postEvent( im
, event
);
403 void InputManager::UpdatePosition()
405 /* Update position */
409 i_length
= var_GetTime( p_input
, "length" ) / 1000000;
410 i_time
= var_GetTime( p_input
, "time");
411 f_pos
= var_GetFloat( p_input
, "position" );
412 emit
positionUpdated( f_pos
, i_time
, i_length
);
415 void InputManager::UpdateNavigation()
417 /* Update navigation status */
418 vlc_value_t val
; val
.i_int
= 0;
419 vlc_value_t val2
; val2
.i_int
= 0;
422 var_Change( p_input
, "title", VLC_VAR_CHOICESCOUNT
, &val
, NULL
);
426 emit
titleChanged( true );
427 msg_Dbg( p_intf
, "Title %"PRId64
, val
.i_int
);
428 /* p_input != NULL since val.i_int != 0 */
429 var_Change( p_input
, "chapter", VLC_VAR_CHOICESCOUNT
, &val2
, NULL
);
430 emit
chapterChanged( (val2
.i_int
> 1) || ( val2
.i_int
> 0 && val
.i_int
> 1 ) );
431 msg_Dbg( p_intf
, "Chapter: %"PRId64
, val2
.i_int
);
434 emit
titleChanged( false );
437 void InputManager::UpdateStatus()
439 /* Update playing status */
440 int state
= var_GetInteger( p_input
, "state" );
441 if( i_old_playing_status
!= state
)
443 i_old_playing_status
= state
;
444 emit
playingStatusChanged( state
);
448 void InputManager::UpdateRate()
451 float f_new_rate
= var_GetFloat( p_input
, "rate" );
452 if( f_new_rate
!= f_rate
)
456 emit
rateChanged( f_rate
);
460 void InputManager::UpdateName()
462 /* Update text, name and nowplaying */
465 /* Try to get the nowplaying */
466 char *format
= var_InheritString( p_intf
, "input-title-format" );
467 char *formated
= str_format_meta( p_input
, format
);
469 name
= qfu(formated
);
472 /* If we have Nothing */
475 char *uri
= input_item_GetURI( input_GetItem( p_input
) );
476 char *file
= uri
? strrchr( uri
, '/' ) : NULL
;
479 decode_URI( ++file
);
487 name
= name
.trimmed();
489 if( oldName
!= name
)
491 emit
nameChanged( name
);
496 int InputManager::playingStatus()
498 return i_old_playing_status
;
501 bool InputManager::hasAudio()
506 var_Change( p_input
, "audio-es", VLC_VAR_CHOICESCOUNT
, &val
, NULL
);
507 return val
.i_int
> 0;
512 bool InputManager::hasVisualisation()
517 aout_instance_t
*aout
= input_GetAout( p_input
);
521 char *visual
= var_InheritString( aout
, "visual" );
522 vlc_object_release( aout
);
531 void InputManager::UpdateTeletext()
535 const bool b_enabled
= var_CountChoices( p_input
, "teletext-es" ) > 0;
536 const int i_teletext_es
= var_GetInteger( p_input
, "teletext-es" );
538 /* Teletext is possible. Show the buttons */
539 emit
teletextPossible( b_enabled
);
541 /* If Teletext is selected */
542 if( b_enabled
&& i_teletext_es
>= 0 )
544 /* Then, find the current page */
546 bool b_transparent
= false;
550 var_DelCallback( p_input_vbi
, "vbi-page", VbiEvent
, this );
551 vlc_object_release( p_input_vbi
);
554 if( input_GetEsObjects( p_input
, i_teletext_es
, &p_input_vbi
, NULL
, NULL
) )
559 /* This callback is not remove explicitly, but interfaces
560 * are guaranted to outlive input */
561 var_AddCallback( p_input_vbi
, "vbi-page", VbiEvent
, this );
563 i_page
= var_GetInteger( p_input_vbi
, "vbi-page" );
564 b_transparent
= !var_GetBool( p_input_vbi
, "vbi-opaque" );
566 emit
newTelexPageSet( i_page
);
567 emit
teletextTransparencyActivated( b_transparent
);
570 emit
teletextActivated( b_enabled
&& i_teletext_es
>= 0 );
574 emit
teletextActivated( false );
575 emit
teletextPossible( false );
579 void InputManager::UpdateEPG()
587 void InputManager::UpdateVout()
591 /* Get current vout lists from input */
593 vout_thread_t
**pp_vout
;
594 if( input_Control( p_input
, INPUT_GET_VOUTS
, &pp_vout
, &i_vout
) )
601 emit
voutListChanged( pp_vout
, i_vout
);
604 bool b_old_video
= b_video
;
605 b_video
= i_vout
> 0;
606 if( !!b_old_video
!= !!b_video
)
607 emit
voutChanged( b_video
);
609 /* Release the vout list */
610 for( size_t i
= 0; i
< i_vout
; i
++ )
611 vlc_object_release( (vlc_object_t
*)pp_vout
[i
] );
615 void InputManager::UpdateAout()
622 void InputManager::UpdateCaching()
624 if(!hasInput()) return;
626 float f_newCache
= var_GetFloat ( p_input
, "cache" );
627 if( f_newCache
!= f_cache
)
629 f_cache
= f_newCache
;
631 emit
cachingChanged( f_cache
);
635 void InputManager::requestArtUpdate()
639 playlist_AskForArtEnqueue( pl_Get(p_intf
), input_GetItem( p_input
) );
643 /* No input will signal the cover art to update,
644 * let's do it ourself */
649 const QString
InputManager::decodeArtURL( input_item_t
*p_item
)
653 char *psz_art
= input_item_GetArtURL( p_item
);
656 char *psz
= make_path( psz_art
);
662 /* Taglib seems to define a attachment://, It won't work yet */
663 url
= url
.replace( "attachment://", "" );
666 QString path
= qfu( psz_art
? psz_art
: "" );
671 void InputManager::UpdateArt()
676 url
= decodeArtURL( input_GetItem( p_input
) );
678 /* the art hasn't changed, no need to update */
682 /* Update Art meta */
684 emit
artChanged( artUrl
);
687 inline void InputManager::UpdateStats()
689 emit
statisticsUpdated( input_GetItem( p_input
) );
692 inline void InputManager::UpdateMeta( input_item_t
*p_item
)
694 emit
metaChanged( p_item
);
697 inline void InputManager::UpdateMeta()
699 emit
currentMetaChanged( input_GetItem( p_input
) );
702 inline void InputManager::UpdateInfo()
704 emit
infoChanged( input_GetItem( p_input
) );
707 void InputManager::UpdateRecord()
711 emit
recordingStateChanged( var_GetBool( p_input
, "record" ) );
715 void InputManager::UpdateProgramEvent()
719 bool b_scrambled
= var_GetBool( p_input
, "program-scrambled" );
720 emit
encryptionChanged( b_scrambled
);
724 /* User update of the slider */
725 void InputManager::sliderUpdate( float new_pos
)
728 var_SetFloat( p_input
, "position", new_pos
);
729 emit
seekRequested( new_pos
);
732 /* User togglePlayPause */
733 void InputManager::togglePlayPause()
737 int state
= var_GetInteger( p_input
, "state" );
738 state
= ( state
!= PLAYING_S
) ? PLAYING_S
: PAUSE_S
;
739 var_SetInteger( p_input
, "state", state
);
743 void InputManager::sectionPrev()
747 int i_type
= var_Type( p_input
, "next-chapter" );
748 var_TriggerCallback( p_input
, (i_type
& VLC_VAR_TYPE
) != 0 ?
749 "prev-chapter":"prev-title" );
753 void InputManager::sectionNext()
757 int i_type
= var_Type( p_input
, "next-chapter" );
758 var_TriggerCallback( p_input
, (i_type
& VLC_VAR_TYPE
) != 0 ?
759 "next-chapter":"next-title" );
763 void InputManager::sectionMenu()
767 vlc_value_t val
, text
;
769 if( var_Change( p_input
, "title 0", VLC_VAR_GETLIST
, &val
, &text
) < 0 )
772 /* XXX is it "Root" or "Title" we want here ?" (set 0 by default) */
774 for( int i
= 0; i
< val
.p_list
->i_count
; i
++ )
776 if( !strcmp( text
.p_list
->p_values
[i
].psz_string
, "Title" ) )
779 var_FreeList( &val
, &text
);
781 var_SetInteger( p_input
, "title 0", root
);
789 /* Set a new Teletext Page */
790 void InputManager::telexSetPage( int page
)
792 if( hasInput() && p_input_vbi
)
794 const int i_teletext_es
= var_GetInteger( p_input
, "teletext-es" );
796 if( i_teletext_es
>= 0 )
798 var_SetInteger( p_input_vbi
, "vbi-page", page
);
799 emit
newTelexPageSet( page
);
804 /* Set the transparency on teletext */
805 void InputManager::telexSetTransparency( bool b_transparentTelextext
)
807 if( hasInput() && p_input_vbi
)
809 var_SetBool( p_input_vbi
, "vbi-opaque", !b_transparentTelextext
);
810 emit
teletextTransparencyActivated( b_transparentTelextext
);
814 void InputManager::activateTeletext( bool b_enable
)
818 if( hasInput() && !var_Change( p_input
, "teletext-es", VLC_VAR_GETLIST
, &list
, &text
) )
820 if( list
.p_list
->i_count
> 0 )
822 /* Prefer the page 100 if it is present */
824 for( i
= 0; i
< text
.p_list
->i_count
; i
++ )
826 /* The description is the page number as a string */
827 const char *psz_page
= text
.p_list
->p_values
[i
].psz_string
;
828 if( psz_page
&& !strcmp( psz_page
, "100" ) )
831 if( i
>= list
.p_list
->i_count
)
833 var_SetInteger( p_input
, "spu-es", b_enable
? list
.p_list
->p_values
[i
].i_int
: -1 );
835 var_FreeList( &list
, &text
);
839 void InputManager::reverse()
843 float f_rate
= var_GetFloat( p_input
, "rate" );
844 var_SetFloat( p_input
, "rate", -f_rate
);
848 void InputManager::slower()
850 var_TriggerCallback( THEPL
, "rate-slower" );
853 void InputManager::faster()
855 var_TriggerCallback( THEPL
, "rate-faster" );
858 void InputManager::littlefaster()
860 var_SetInteger( p_intf
->p_libvlc
, "key-action", ACTIONID_RATE_FASTER_FINE
);
863 void InputManager::littleslower()
865 var_SetInteger( p_intf
->p_libvlc
, "key-action", ACTIONID_RATE_SLOWER_FINE
);
868 void InputManager::normalRate()
870 var_SetFloat( THEPL
, "rate", 1. );
873 void InputManager::setRate( int new_rate
)
875 var_SetFloat( THEPL
, "rate",
876 (float)INPUT_RATE_DEFAULT
/ (float)new_rate
);
879 void InputManager::jumpFwd()
881 int i_interval
= var_InheritInteger( p_input
, "short-jump-size" );
884 mtime_t val
= (mtime_t
)(i_interval
) * 1000000L;
885 var_SetTime( p_input
, "time-offset", val
);
889 void InputManager::jumpBwd()
891 int i_interval
= var_InheritInteger( p_input
, "short-jump-size" );
894 mtime_t val
= -1 *(mtime_t
)(i_interval
) * 1000000L;
895 var_SetTime( p_input
, "time-offset", val
);
899 void InputManager::setAtoB()
903 timeA
= var_GetTime( THEMIM
->getInput(), "time" );
907 timeB
= var_GetTime( THEMIM
->getInput(), "time" );
908 var_SetTime( THEMIM
->getInput(), "time" , timeA
);
909 CONNECT( this, positionUpdated( float, int64_t, int ),
910 this, AtoBLoop( float, int64_t, int ) );
916 disconnect( this, SIGNAL( positionUpdated( float, int64_t, int ) ),
917 this, SLOT( AtoBLoop( float, int64_t, int ) ) );
919 emit
AtoBchanged( (timeA
!= 0 ), (timeB
!= 0 ) );
922 /* Function called regularly when in an AtoB loop */
923 void InputManager::AtoBLoop( float, int64_t i_time
, int )
927 if( i_time
>= timeB
|| i_time
< timeA
)
928 var_SetTime( THEMIM
->getInput(), "time" , timeA
);
932 /**********************************************************************
933 * MainInputManager implementation. Wrap an input manager and
934 * take care of updating the main playlist input.
935 * Used in the main playlist Dialog
936 **********************************************************************/
938 MainInputManager::MainInputManager( intf_thread_t
*_p_intf
)
939 : QObject(NULL
), p_intf( _p_intf
)
942 im
= new InputManager( this, p_intf
);
944 var_AddCallback( THEPL
, "item-change", ItemChanged
, im
);
945 var_AddCallback( THEPL
, "item-current", PLItemChanged
, this );
946 var_AddCallback( THEPL
, "activity", PLItemChanged
, this );
947 var_AddCallback( THEPL
, "leaf-to-parent", LeafToParent
, this );
948 var_AddCallback( THEPL
, "playlist-item-append", PLItemAppended
, this );
949 var_AddCallback( THEPL
, "playlist-item-deleted", PLItemRemoved
, this );
950 var_AddCallback( THEPL
, "random", RandomChanged
, this );
951 var_AddCallback( THEPL
, "repeat", RepeatChanged
, this );
952 var_AddCallback( THEPL
, "loop", LoopChanged
, this );
954 var_AddCallback( THEPL
, "volume", VolumeChanged
, this );
955 var_AddCallback( THEPL
, "mute", SoundMuteChanged
, this );
957 /* Warn our embedded IM about input changes */
958 DCONNECT( this, inputChanged( input_thread_t
* ),
959 im
, setInput( input_thread_t
* ) );
963 MainInputManager::~MainInputManager()
967 emit
inputChanged( NULL
);
968 var_DelCallback( p_input
, "state", PLItemChanged
, this );
969 vlc_object_release( p_input
);
972 var_DelCallback( THEPL
, "volume", VolumeChanged
, this );
973 var_DelCallback( THEPL
, "mute", SoundMuteChanged
, this );
975 var_DelCallback( THEPL
, "activity", PLItemChanged
, this );
976 var_DelCallback( THEPL
, "item-change", ItemChanged
, im
);
977 var_DelCallback( THEPL
, "leaf-to-parent", LeafToParent
, this );
979 var_DelCallback( THEPL
, "item-current", PLItemChanged
, this );
980 var_DelCallback( THEPL
, "playlist-item-append", PLItemAppended
, this );
981 var_DelCallback( THEPL
, "playlist-item-deleted", PLItemRemoved
, this );
982 var_DelCallback( THEPL
, "random", RandomChanged
, this );
983 var_DelCallback( THEPL
, "repeat", RepeatChanged
, this );
984 var_DelCallback( THEPL
, "loop", LoopChanged
, this );
988 vout_thread_t
* MainInputManager::getVout()
990 return p_input
? input_GetVout( p_input
) : NULL
;
993 aout_instance_t
* MainInputManager::getAout()
995 return p_input
? input_GetAout( p_input
) : NULL
;
998 void MainInputManager::customEvent( QEvent
*event
)
1000 int type
= event
->type();
1004 // msg_Dbg( p_intf, "New MainIM Event of type: %i", type );
1007 case VolumeChanged_Type
:
1008 emit
volumeChanged();
1010 case SoundMuteChanged_Type
:
1011 emit
soundMuteChanged();
1013 case PLItemAppended_Type
:
1014 plEv
= static_cast<PLEvent
*>( event
);
1015 emit
playlistItemAppended( plEv
->i_item
, plEv
->i_parent
);
1017 case PLItemRemoved_Type
:
1018 plEv
= static_cast<PLEvent
*>( event
);
1019 emit
playlistItemRemoved( plEv
->i_item
);
1021 case RandomChanged_Type
:
1022 emit
randomChanged( var_GetBool( THEPL
, "random" ) );
1024 case LoopChanged_Type
:
1025 case RepeatChanged_Type
:
1028 case LeafToParent_Type
:
1029 plEv
= static_cast<PLEvent
*>( event
);
1030 emit
leafBecameParent( plEv
->i_item
);
1033 if( type
!= ItemChanged_Type
) return;
1036 /* Should be PLItemChanged Event */
1037 if( !p_intf
->p_sys
->b_isDialogProvider
)
1039 if( p_input
&& ( p_input
->b_dead
|| !vlc_object_alive (p_input
) ) )
1041 emit
inputChanged( p_input
);
1042 var_DelCallback( p_input
, "state", PLItemChanged
, this );
1043 vlc_object_release( p_input
);
1050 p_input
= playlist_CurrentInput(THEPL
);
1053 var_AddCallback( p_input
, "state", PLItemChanged
, this );
1054 emit
inputChanged( p_input
);
1060 /* remove previous stored p_input */
1063 vlc_object_release( p_input
);
1066 /* we are working as a dialogs provider */
1067 p_input
= playlist_CurrentInput( pl_Get(p_intf
) );
1070 emit
inputChanged( p_input
);
1075 /* Playlist Control functions */
1076 void MainInputManager::stop()
1078 playlist_Stop( THEPL
);
1081 void MainInputManager::next()
1083 playlist_Next( THEPL
);
1086 void MainInputManager::prev()
1088 playlist_Prev( THEPL
);
1091 void MainInputManager::prevOrReset()
1093 if( !p_input
|| var_GetTime( p_input
, "time") < 10000 )
1094 playlist_Prev( THEPL
);
1096 getIM()->sliderUpdate( 0.0 );
1099 void MainInputManager::togglePlayPause()
1101 /* No input, play */
1103 playlist_Play( THEPL
);
1105 getIM()->togglePlayPause();
1108 void MainInputManager::play()
1110 /* No input, play */
1112 playlist_Play( THEPL
);
1115 if( PLAYING_S
!= var_GetInteger( p_input
, "state" ) )
1117 getIM()->togglePlayPause();
1122 void MainInputManager::pause()
1124 if(p_input
&& PLAYING_S
== var_GetInteger( p_input
, "state" ) )
1126 getIM()->togglePlayPause();
1130 void MainInputManager::toggleRandom()
1132 var_ToggleBool( THEPL
, "random" );
1135 void MainInputManager::notifyRepeatLoop()
1137 int i_value
= var_GetBool( THEPL
, "loop" ) * REPEAT_ALL
1138 + var_GetBool( THEPL
, "repeat" ) * REPEAT_ONE
;
1140 emit
repeatLoopChanged( i_value
);
1143 void MainInputManager::loopRepeatLoopStatus()
1145 /* Toggle Normal -> Loop -> Repeat -> Normal ... */
1146 if( var_GetBool( THEPL
, "repeat" ) )
1147 var_SetBool( THEPL
, "repeat", false );
1148 else if( var_GetBool( THEPL
, "loop" ) )
1150 var_SetBool( THEPL
, "loop", false );
1151 var_SetBool( THEPL
, "repeat", true );
1154 var_SetBool( THEPL
, "loop", true );
1157 void MainInputManager::activatePlayQuit( bool b_exit
)
1159 var_SetBool( THEPL
, "play-and-exit", b_exit
);
1162 bool MainInputManager::getPlayExitState()
1164 return var_GetBool( THEPL
, "play-and-exit" );
1167 /****************************
1168 * Static callbacks for MIM *
1169 ****************************/
1170 static int PLItemChanged( vlc_object_t
*p_this
, const char *psz_var
,
1171 vlc_value_t oldval
, vlc_value_t
, void *param
)
1173 VLC_UNUSED( p_this
); VLC_UNUSED( psz_var
); VLC_UNUSED( oldval
);
1175 MainInputManager
*mim
= (MainInputManager
*)param
;
1177 IMEvent
*event
= new IMEvent( ItemChanged_Type
);
1178 QApplication::postEvent( mim
, event
);
1182 static int LeafToParent( vlc_object_t
*p_this
, const char *psz_var
,
1183 vlc_value_t oldval
, vlc_value_t newval
, void *param
)
1185 VLC_UNUSED( p_this
); VLC_UNUSED( psz_var
); VLC_UNUSED( oldval
);
1186 MainInputManager
*mim
= (MainInputManager
*)param
;
1188 PLEvent
*event
= new PLEvent( LeafToParent_Type
, newval
.i_int
);
1190 QApplication::postEvent( mim
, event
);
1194 static int VolumeChanged( 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
); VLC_UNUSED( newval
);
1199 MainInputManager
*mim
= (MainInputManager
*)param
;
1201 IMEvent
*event
= new IMEvent( VolumeChanged_Type
);
1202 QApplication::postEvent( mim
, event
);
1206 static int SoundMuteChanged( 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( SoundMuteChanged_Type
);
1214 QApplication::postEvent( mim
, event
);
1218 static int PLItemAppended
1219 ( vlc_object_t
* obj
, const char *var
, vlc_value_t old
, vlc_value_t cur
, void *data
)
1221 VLC_UNUSED( obj
); VLC_UNUSED( var
); VLC_UNUSED( old
);
1223 MainInputManager
*mim
= static_cast<MainInputManager
*>(data
);
1224 playlist_add_t
*p_add
= static_cast<playlist_add_t
*>( cur
.p_address
);
1226 PLEvent
*event
= new PLEvent( PLItemAppended_Type
, p_add
->i_item
, p_add
->i_node
);
1227 QApplication::postEvent( mim
, event
);
1230 static int PLItemRemoved
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
);
1235 MainInputManager
*mim
= static_cast<MainInputManager
*>(data
);
1237 PLEvent
*event
= new PLEvent( PLItemRemoved_Type
, cur
.i_int
, 0 );
1238 QApplication::postEvent( mim
, event
);
1242 static int RandomChanged
1243 ( vlc_object_t
* obj
, const char *var
, vlc_value_t old
, vlc_value_t cur
, void *data
)
1245 VLC_UNUSED( obj
); VLC_UNUSED( var
); VLC_UNUSED( old
); VLC_UNUSED( cur
);
1247 MainInputManager
*mim
= static_cast<MainInputManager
*>(data
);
1249 IMEvent
*event
= new IMEvent( RandomChanged_Type
);
1250 QApplication::postEvent( mim
, event
);
1254 /* Probably could be merged with next callback */
1255 static int LoopChanged
1256 ( vlc_object_t
* obj
, const char *var
, vlc_value_t old
, vlc_value_t cur
, void *data
)
1258 VLC_UNUSED( obj
); VLC_UNUSED( var
); VLC_UNUSED( old
); VLC_UNUSED( cur
);
1260 MainInputManager
*mim
= static_cast<MainInputManager
*>(data
);
1262 IMEvent
*event
= new IMEvent( LoopChanged_Type
);
1263 QApplication::postEvent( mim
, event
);
1267 static int RepeatChanged
1268 ( vlc_object_t
* obj
, const char *var
, vlc_value_t old
, vlc_value_t cur
, void *data
)
1270 VLC_UNUSED( obj
); VLC_UNUSED( var
); VLC_UNUSED( old
); VLC_UNUSED( cur
);
1272 MainInputManager
*mim
= static_cast<MainInputManager
*>(data
);
1274 IMEvent
*event
= new IMEvent( RepeatChanged_Type
);
1275 QApplication::postEvent( mim
, event
);