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"
36 #include <QApplication>
40 static int ItemChanged( vlc_object_t *, const char *,
41 vlc_value_t, vlc_value_t, void * );
42 static int LeafToParent( vlc_object_t *, const char *,
43 vlc_value_t, vlc_value_t, void * );
44 static int PLItemChanged( vlc_object_t *, const char *,
45 vlc_value_t, vlc_value_t, void * );
46 static int PLItemAppended( vlc_object_t *, const char *,
47 vlc_value_t, vlc_value_t, void * );
48 static int PLItemRemoved( vlc_object_t *, const char *,
49 vlc_value_t, vlc_value_t, void * );
50 static int VolumeChanged( vlc_object_t *, const char *,
51 vlc_value_t, vlc_value_t, void * );
52 static int SoundMuteChanged( vlc_object_t *, const char *,
53 vlc_value_t, vlc_value_t, void * );
55 static int RandomChanged( vlc_object_t *, const char *,
56 vlc_value_t, vlc_value_t, void * );
57 static int LoopChanged( vlc_object_t *, const char *,
58 vlc_value_t, vlc_value_t, void * );
59 static int RepeatChanged( vlc_object_t *, const char *,
60 vlc_value_t, vlc_value_t, void * );
63 static int InputEvent( vlc_object_t *, const char *,
64 vlc_value_t, vlc_value_t, void * );
65 static int VbiEvent( vlc_object_t *, const char *,
66 vlc_value_t, vlc_value_t, void * );
69 /**********************************************************************
70 * InputManager implementation
71 **********************************************************************
72 * The Input Manager can be the main one around the playlist
73 * But can also be used for VLM dialog or similar
74 **********************************************************************/
76 InputManager::InputManager( QObject *parent, intf_thread_t *_p_intf) :
77 QObject( parent ), p_intf( _p_intf )
79 i_old_playing_status = END_S;
89 f_cache = -1.; /* impossible initial value, different from all */
92 InputManager::~InputManager()
97 /* Define the Input used.
98 Add the callbacks on input
99 p_input is held once here */
100 void InputManager::setInput( input_thread_t *_p_input )
104 if( p_input && !( p_input->b_dead || !vlc_object_alive (p_input) ) )
106 msg_Dbg( p_intf, "IM: Setting an input" );
107 vlc_object_hold( p_input );
116 p_item = input_GetItem( p_input );
117 emit rateChanged( var_GetFloat( p_input, "rate" ) );
123 assert( !p_input_vbi );
124 emit rateChanged( var_InheritFloat( p_intf, "rate" ) );
128 /* delete Input if it ever existed.
129 Delete the callbacls on input
130 p_input is released once here */
131 void InputManager::delInput()
133 if( !p_input ) return;
134 msg_Dbg( p_intf, "IM: Deleting the input" );
137 i_old_playing_status = END_S;
148 vlc_object_release( p_input_vbi );
152 vlc_object_release( p_input );
155 emit positionUpdated( -1.0, 0 ,0 );
156 emit rateChanged( var_InheritFloat( p_intf, "rate" ) );
157 emit nameChanged( "" );
158 emit chapterChanged( 0 );
159 emit titleChanged( 0 );
160 emit playingStatusChanged( END_S );
162 emit teletextPossible( false );
163 emit AtoBchanged( false, false );
164 emit voutChanged( false );
165 emit voutListChanged( NULL, 0 );
167 /* Reset all InfoPanels but stats */
168 emit artChanged( NULL );
169 emit infoChanged( NULL );
170 emit currentMetaChanged( (input_item_t *)NULL );
172 emit encryptionChanged( false );
173 emit recordingStateChanged( false );
175 emit cachingChanged( 1 );
178 /* Convert the event from the callbacks in actions */
179 void InputManager::customEvent( QEvent *event )
181 int i_type = event->type();
182 IMEvent *ple = static_cast<IMEvent *>(event);
184 if( i_type == ItemChanged_Type )
185 UpdateMeta( ple->p_item );
193 case PositionUpdate_Type:
196 case StatisticsUpdate_Type:
199 case ItemChanged_Type:
200 /* Ignore ItemChanged_Type event that does not apply to our input */
201 if( p_item == ple->p_item )
206 /* Update duration of file */
209 case ItemStateChanged_Type:
210 // TODO: Fusion with above state
213 // UpdateNavigation(); This shouldn't be useful now
214 // UpdateTeletext(); Same
216 case NameChanged_Type:
219 case MetaChanged_Type:
221 UpdateName(); /* Needed for NowPlaying */
222 UpdateArt(); /* Art is part of meta in the core */
224 case InfoChanged_Type:
227 case ItemTitleChanged_Type:
229 UpdateName(); /* Display the name of the Chapter, if exists */
231 case ItemRateChanged_Type:
234 case ItemEsChanged_Type:
236 // We don't do anything ES related. Why ?
238 case ItemTeletextChanged_Type:
241 case InterfaceVoutUpdate_Type:
244 case SynchroChanged_Type:
245 emit synchroChanged();
247 case CachingEvent_Type:
250 case BookmarksChanged_Type:
251 emit bookmarksChanged();
253 case InterfaceAoutUpdate_Type:
256 case RecordingEvent_Type:
259 case ProgramChanged_Type:
260 UpdateProgramEvent();
266 msg_Warn( p_intf, "This shouldn't happen: %i", i_type );
271 /* Add the callbacks on Input. Self explanatory */
272 inline void InputManager::addCallbacks()
274 var_AddCallback( p_input, "intf-event", InputEvent, this );
277 /* Delete the callbacks on Input. Self explanatory */
278 inline void InputManager::delCallbacks()
280 var_DelCallback( p_input, "intf-event", InputEvent, this );
283 /* Static callbacks for IM */
284 static int ItemChanged( vlc_object_t *p_this, const char *psz_var,
285 vlc_value_t oldval, vlc_value_t newval, void *param )
287 InputManager *im = (InputManager*)param;
288 input_item_t *p_item = static_cast<input_item_t *>(newval.p_address);
290 IMEvent *event = new IMEvent( ItemChanged_Type, p_item );
291 QApplication::postEvent( im, event );
295 static int InputEvent( vlc_object_t *p_this, const char *,
296 vlc_value_t, vlc_value_t newval, void *param )
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" ) / 1000000;
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 emit titleChanged( true );
422 msg_Dbg( p_intf, "Title %"PRId64, val.i_int );
423 /* p_input != NULL since val.i_int != 0 */
424 var_Change( p_input, "chapter", VLC_VAR_CHOICESCOUNT, &val2, NULL );
425 emit chapterChanged( (val2.i_int > 1) || ( val2.i_int > 0 && val.i_int > 1 ) );
426 msg_Dbg( p_intf, "Chapter: %"PRId64, val2.i_int );
429 emit titleChanged( false );
432 void InputManager::UpdateStatus()
434 /* Update playing status */
435 int state = var_GetInteger( p_input, "state" );
436 if( i_old_playing_status != state )
438 i_old_playing_status = state;
439 emit playingStatusChanged( state );
443 void InputManager::UpdateRate()
446 float f_new_rate = var_GetFloat( p_input, "rate" );
447 if( f_new_rate != f_rate )
451 emit rateChanged( f_rate );
455 void InputManager::UpdateName()
457 /* Update text, name and nowplaying */
460 /* Try to get the Title, then the Name */
461 char *psz_name = input_item_GetTitleFbName( input_GetItem( p_input ) );
463 /* Try to get the nowplaying */
464 char *psz_nowplaying =
465 input_item_GetNowPlaying( input_GetItem( p_input ) );
466 if( !EMPTY_STR( psz_nowplaying ) )
468 text.sprintf( "%s - %s", psz_nowplaying, psz_name );
470 else /* Do it ourself */
472 char *psz_artist = input_item_GetArtist( input_GetItem( p_input ) );
474 if( !EMPTY_STR( psz_artist ) )
475 text.sprintf( "%s - %s", psz_artist, psz_name );
477 text.sprintf( "%s", psz_name );
481 /* Free everything */
483 free( psz_nowplaying );
485 /* If we have Nothing */
488 psz_name = input_item_GetURI( input_GetItem( p_input ) );
489 text.sprintf( "%s", psz_name );
490 text = text.remove( 0, text.lastIndexOf( DIR_SEP ) + 1 );
494 if( oldName != text )
496 emit nameChanged( text );
501 int InputManager::playingStatus()
503 return i_old_playing_status;
506 bool InputManager::hasAudio()
511 var_Change( p_input, "audio-es", VLC_VAR_CHOICESCOUNT, &val, NULL );
512 return val.i_int > 0;
517 void InputManager::UpdateTeletext()
521 const bool b_enabled = var_CountChoices( p_input, "teletext-es" ) > 0;
522 const int i_teletext_es = var_GetInteger( p_input, "teletext-es" );
524 /* Teletext is possible. Show the buttons */
525 emit teletextPossible( b_enabled );
527 /* If Teletext is selected */
528 if( b_enabled && i_teletext_es >= 0 )
530 /* Then, find the current page */
532 bool b_transparent = false;
536 var_DelCallback( p_input_vbi, "vbi-page", VbiEvent, this );
537 vlc_object_release( p_input_vbi );
540 if( input_GetEsObjects( p_input, i_teletext_es, &p_input_vbi, NULL, NULL ) )
545 /* This callback is not remove explicitly, but interfaces
546 * are guaranted to outlive input */
547 var_AddCallback( p_input_vbi, "vbi-page", VbiEvent, this );
549 i_page = var_GetInteger( p_input_vbi, "vbi-page" );
550 b_transparent = !var_GetBool( p_input_vbi, "vbi-opaque" );
552 emit newTelexPageSet( i_page );
553 emit teletextTransparencyActivated( b_transparent );
556 emit teletextActivated( b_enabled && i_teletext_es >= 0 );
560 emit teletextActivated( false );
561 emit teletextPossible( false );
565 void InputManager::UpdateEPG()
573 void InputManager::UpdateVout()
577 /* Get current vout lists from input */
579 vout_thread_t **pp_vout;
580 if( input_Control( p_input, INPUT_GET_VOUTS, &pp_vout, &i_vout ) )
587 emit voutListChanged( pp_vout, i_vout );
590 bool b_old_video = b_video;
591 b_video = i_vout > 0;
592 if( !!b_old_video != !!b_video )
593 emit voutChanged( b_video );
595 /* Release the vout list */
596 for( int i = 0; i < i_vout; i++ )
597 vlc_object_release( (vlc_object_t*)pp_vout[i] );
601 void InputManager::UpdateAout()
608 void InputManager::UpdateCaching()
610 if(!hasInput()) return;
612 float f_newCache = var_GetFloat ( p_input, "cache" );
613 if( f_newCache != f_cache )
615 f_cache = f_newCache;
617 emit cachingChanged( f_cache );
621 void InputManager::requestArtUpdate()
625 playlist_AskForArtEnqueue( pl_Get(p_intf), input_GetItem( p_input ) );
629 /* No input will signal the cover art to update,
630 * let's do it ourself */
635 const QString InputManager::decodeArtURL( input_item_t *p_item )
639 char *psz_art = input_item_GetArtURL( p_item );
642 char *psz = make_path( psz_art );
648 /* Taglib seems to define a attachment://, It won't work yet */
649 url = url.replace( "attachment://", "" );
652 QString path = qfu( psz_art ? psz_art : "" );
657 void InputManager::UpdateArt()
662 url = decodeArtURL( input_GetItem( p_input ) );
664 /* the art hasn't changed, no need to update */
668 /* Update Art meta */
670 emit artChanged( artUrl );
673 inline void InputManager::UpdateStats()
675 emit statisticsUpdated( input_GetItem( p_input ) );
678 inline void InputManager::UpdateMeta( input_item_t *p_item )
680 emit metaChanged( p_item );
683 inline void InputManager::UpdateMeta()
685 emit currentMetaChanged( input_GetItem( p_input ) );
688 inline void InputManager::UpdateInfo()
690 emit infoChanged( input_GetItem( p_input ) );
693 void InputManager::UpdateRecord()
697 emit recordingStateChanged( var_GetBool( p_input, "record" ) );
701 void InputManager::UpdateProgramEvent()
705 bool b_scrambled = var_GetBool( p_input, "program-scrambled" );
706 emit encryptionChanged( b_scrambled );
710 /* User update of the slider */
711 void InputManager::sliderUpdate( float new_pos )
714 var_SetFloat( p_input, "position", new_pos );
715 emit seekRequested( new_pos );
718 /* User togglePlayPause */
719 void InputManager::togglePlayPause()
723 int state = var_GetInteger( p_input, "state" );
724 state = ( state != PLAYING_S ) ? PLAYING_S : PAUSE_S;
725 var_SetInteger( p_input, "state", state );
729 void InputManager::sectionPrev()
733 int i_type = var_Type( p_input, "next-chapter" );
734 var_TriggerCallback( p_input, (i_type & VLC_VAR_TYPE) != 0 ?
735 "prev-chapter":"prev-title" );
739 void InputManager::sectionNext()
743 int i_type = var_Type( p_input, "next-chapter" );
744 var_TriggerCallback( p_input, (i_type & VLC_VAR_TYPE) != 0 ?
745 "next-chapter":"next-title" );
749 void InputManager::sectionMenu()
753 vlc_value_t val, text;
755 if( var_Change( p_input, "title 0", VLC_VAR_GETLIST, &val, &text ) < 0 )
758 /* XXX is it "Root" or "Title" we want here ?" (set 0 by default) */
760 for( int i = 0; i < val.p_list->i_count; i++ )
762 if( !strcmp( text.p_list->p_values[i].psz_string, "Title" ) )
765 var_FreeList( &val, &text );
767 var_SetInteger( p_input, "title 0", root );
775 /* Set a new Teletext Page */
776 void InputManager::telexSetPage( int page )
778 if( hasInput() && p_input_vbi )
780 const int i_teletext_es = var_GetInteger( p_input, "teletext-es" );
782 if( i_teletext_es >= 0 )
784 var_SetInteger( p_input_vbi, "vbi-page", page );
785 emit newTelexPageSet( page );
790 /* Set the transparency on teletext */
791 void InputManager::telexSetTransparency( bool b_transparentTelextext )
793 if( hasInput() && p_input_vbi )
795 var_SetBool( p_input_vbi, "vbi-opaque", !b_transparentTelextext );
796 emit teletextTransparencyActivated( b_transparentTelextext );
800 void InputManager::activateTeletext( bool b_enable )
804 if( hasInput() && !var_Change( p_input, "teletext-es", VLC_VAR_GETLIST, &list, &text ) )
806 if( list.p_list->i_count > 0 )
808 /* Prefer the page 100 if it is present */
810 for( i = 0; i < text.p_list->i_count; i++ )
812 /* The description is the page number as a string */
813 const char *psz_page = text.p_list->p_values[i].psz_string;
814 if( psz_page && !strcmp( psz_page, "100" ) )
817 if( i >= list.p_list->i_count )
819 var_SetInteger( p_input, "spu-es", b_enable ? list.p_list->p_values[i].i_int : -1 );
821 var_FreeList( &list, &text );
825 void InputManager::reverse()
829 float f_rate = var_GetFloat( p_input, "rate" );
830 var_SetFloat( p_input, "rate", -f_rate );
834 void InputManager::slower()
836 var_TriggerCallback( THEPL, "rate-slower" );
839 void InputManager::faster()
841 var_TriggerCallback( THEPL, "rate-faster" );
844 void InputManager::littlefaster()
846 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_RATE_FASTER_FINE );
849 void InputManager::littleslower()
851 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_RATE_SLOWER_FINE );
854 void InputManager::normalRate()
856 var_SetFloat( THEPL, "rate", 1. );
859 void InputManager::setRate( int new_rate )
861 var_SetFloat( THEPL, "rate",
862 (float)INPUT_RATE_DEFAULT / (float)new_rate );
865 void InputManager::jumpFwd()
867 int i_interval = var_InheritInteger( p_input, "short-jump-size" );
870 mtime_t val = (mtime_t)(i_interval) * 1000000L;
871 var_SetTime( p_input, "time-offset", val );
875 void InputManager::jumpBwd()
877 int i_interval = var_InheritInteger( p_input, "short-jump-size" );
880 mtime_t val = -1 *(mtime_t)(i_interval) * 1000000L;
881 var_SetTime( p_input, "time-offset", val );
885 void InputManager::setAtoB()
889 timeA = var_GetTime( THEMIM->getInput(), "time" );
893 timeB = var_GetTime( THEMIM->getInput(), "time" );
894 var_SetTime( THEMIM->getInput(), "time" , timeA );
895 CONNECT( this, positionUpdated( float, int64_t, int ),
896 this, AtoBLoop( float, int64_t, int ) );
902 disconnect( this, SIGNAL( positionUpdated( float, int64_t, int ) ),
903 this, SLOT( AtoBLoop( float, int64_t, int ) ) );
905 emit AtoBchanged( (timeA != 0 ), (timeB != 0 ) );
908 /* Function called regularly when in an AtoB loop */
909 void InputManager::AtoBLoop( float, int64_t i_time, int )
913 if( i_time >= timeB || i_time < timeA )
914 var_SetTime( THEMIM->getInput(), "time" , timeA );
918 /**********************************************************************
919 * MainInputManager implementation. Wrap an input manager and
920 * take care of updating the main playlist input.
921 * Used in the main playlist Dialog
922 **********************************************************************/
923 MainInputManager * MainInputManager::instance = NULL;
925 MainInputManager::MainInputManager( intf_thread_t *_p_intf )
926 : QObject(NULL), p_intf( _p_intf )
929 im = new InputManager( this, p_intf );
931 var_AddCallback( THEPL, "item-change", ItemChanged, im );
932 var_AddCallback( THEPL, "item-current", PLItemChanged, this );
933 var_AddCallback( THEPL, "activity", PLItemChanged, this );
934 var_AddCallback( THEPL, "leaf-to-parent", LeafToParent, this );
935 var_AddCallback( THEPL, "playlist-item-append", PLItemAppended, this );
936 var_AddCallback( THEPL, "playlist-item-deleted", PLItemRemoved, this );
937 var_AddCallback( THEPL, "random", RandomChanged, this );
938 var_AddCallback( THEPL, "repeat", RepeatChanged, this );
939 var_AddCallback( THEPL, "loop", LoopChanged, this );
941 var_AddCallback( THEPL, "volume-change", VolumeChanged, this );
942 var_AddCallback( THEPL, "volume-muted", SoundMuteChanged, this );
944 /* Warn our embedded IM about input changes */
945 DCONNECT( this, inputChanged( input_thread_t * ),
946 im, setInput( input_thread_t * ) );
948 /* emit check if playlist has already started playing */
949 input_thread_t *p_input = playlist_CurrentInput( THEPL );
952 input_item_t *p_item = input_GetItem( p_input );
955 IMEvent *event = new IMEvent( ItemChanged_Type, p_item );
956 customEvent( event );
959 vlc_object_release( p_input );
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-change", VolumeChanged, this );
973 var_DelCallback( THEPL, "volume-muted", 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();
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 imEv = static_cast<IMEvent*>( event );
1031 emit leafBecameParent( imEv->p_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::togglePlayPause()
1093 /* No input, play */
1095 playlist_Play( THEPL );
1097 getIM()->togglePlayPause();
1100 void MainInputManager::play()
1102 /* No input, play */
1104 playlist_Play( THEPL );
1107 if( PLAYING_S != var_GetInteger( p_input, "state" ) )
1109 getIM()->togglePlayPause();
1114 void MainInputManager::pause()
1116 if(p_input && PLAYING_S == var_GetInteger( p_input, "state" ) )
1118 getIM()->togglePlayPause();
1122 void MainInputManager::toggleRandom()
1124 var_ToggleBool( THEPL, "random" );
1127 void MainInputManager::notifyRepeatLoop()
1129 int i_value = var_GetBool( THEPL, "loop" ) * REPEAT_ALL
1130 + var_GetBool( THEPL, "repeat" ) * REPEAT_ONE;
1132 emit repeatLoopChanged( i_value );
1135 void MainInputManager::loopRepeatLoopStatus()
1137 /* Toggle Normal -> Loop -> Repeat -> Normal ... */
1138 if( var_GetBool( THEPL, "repeat" ) )
1139 var_SetBool( THEPL, "repeat", false );
1140 else if( var_GetBool( THEPL, "loop" ) )
1142 var_SetBool( THEPL, "loop", false );
1143 var_SetBool( THEPL, "repeat", true );
1146 var_SetBool( THEPL, "loop", true );
1149 void MainInputManager::activatePlayQuit( bool b_exit )
1151 var_SetBool( THEPL, "play-and-exit", b_exit );
1154 bool MainInputManager::getPlayExitState()
1156 return var_GetBool( THEPL, "play-and-exit" );
1159 /****************************
1160 * Static callbacks for MIM *
1161 ****************************/
1162 static int PLItemChanged( vlc_object_t *p_this, const char *psz_var,
1163 vlc_value_t oldval, vlc_value_t, void *param )
1165 MainInputManager *mim = (MainInputManager*)param;
1167 IMEvent *event = new IMEvent( ItemChanged_Type );
1168 QApplication::postEvent( mim, event );
1172 static int LeafToParent( vlc_object_t *p_this, const char *psz_var,
1173 vlc_value_t oldval, vlc_value_t newval, void *param )
1175 MainInputManager *mim = (MainInputManager*)param;
1177 IMEvent *event = new IMEvent( LeafToParent_Type,
1178 static_cast<input_item_t*>( newval.p_address ) );
1179 QApplication::postEvent( mim, event );
1183 static int VolumeChanged( vlc_object_t *p_this, const char *psz_var,
1184 vlc_value_t oldval, vlc_value_t newval, void *param )
1186 MainInputManager *mim = (MainInputManager*)param;
1188 IMEvent *event = new IMEvent( VolumeChanged_Type );
1189 QApplication::postEvent( mim, event );
1193 static int SoundMuteChanged( vlc_object_t *p_this, const char *psz_var,
1194 vlc_value_t oldval, vlc_value_t newval, void *param )
1196 MainInputManager *mim = (MainInputManager*)param;
1198 IMEvent *event = new IMEvent( SoundMuteChanged_Type );
1199 QApplication::postEvent( mim, event );
1203 static int PLItemAppended
1204 ( vlc_object_t * obj, const char *var, vlc_value_t old, vlc_value_t cur, void *data )
1206 MainInputManager *mim = static_cast<MainInputManager*>(data);
1207 playlist_add_t *p_add = static_cast<playlist_add_t*>( cur.p_address );
1209 PLEvent *event = new PLEvent( PLItemAppended_Type, p_add->i_item, p_add->i_node );
1210 QApplication::postEvent( mim, event );
1213 static int PLItemRemoved
1214 ( vlc_object_t * obj, const char *var, vlc_value_t old, vlc_value_t cur, void *data )
1216 MainInputManager *mim = static_cast<MainInputManager*>(data);
1218 PLEvent *event = new PLEvent( PLItemRemoved_Type, cur.i_int, 0 );
1219 QApplication::postEvent( mim, event );
1223 static int RandomChanged
1224 ( vlc_object_t * obj, const char *var, vlc_value_t old, vlc_value_t cur, void *data )
1226 MainInputManager *mim = static_cast<MainInputManager*>(data);
1228 IMEvent *event = new IMEvent( RandomChanged_Type );
1229 QApplication::postEvent( mim, event );
1233 /* Probably could be merged with next callback */
1234 static int LoopChanged
1235 ( vlc_object_t * obj, const char *var, vlc_value_t old, vlc_value_t cur, void *data )
1237 MainInputManager *mim = static_cast<MainInputManager*>(data);
1239 IMEvent *event = new IMEvent( LoopChanged_Type );
1240 QApplication::postEvent( mim, event );
1244 static int RepeatChanged
1245 ( vlc_object_t * obj, const char *var, vlc_value_t old, vlc_value_t cur, void *data )
1247 MainInputManager *mim = static_cast<MainInputManager*>(data);
1249 IMEvent *event = new IMEvent( RepeatChanged_Type );
1250 QApplication::postEvent( mim, event );