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 RandomChanged( vlc_object_t *, const char *,
60 vlc_value_t, vlc_value_t, void * );
61 static int LoopChanged( vlc_object_t *, const char *,
62 vlc_value_t, vlc_value_t, void * );
63 static int RepeatChanged( vlc_object_t *, const char *,
64 vlc_value_t, vlc_value_t, void * );
67 static int InputEvent( vlc_object_t *, const char *,
68 vlc_value_t, vlc_value_t, void * );
69 static int VbiEvent( vlc_object_t *, const char *,
70 vlc_value_t, vlc_value_t, void * );
73 /**********************************************************************
74 * InputManager implementation
75 **********************************************************************
76 * The Input Manager can be the main one around the playlist
77 * But can also be used for VLM dialog or similar
78 **********************************************************************/
80 InputManager::InputManager( QObject *parent, intf_thread_t *_p_intf) :
81 QObject( parent ), p_intf( _p_intf )
83 i_old_playing_status = END_S;
93 f_cache = -1.; /* impossible initial value, different from all */
96 InputManager::~InputManager()
101 /* Define the Input used.
102 Add the callbacks on input
103 p_input is held once here */
104 void InputManager::setInput( input_thread_t *_p_input )
108 if( p_input && !( p_input->b_dead || !vlc_object_alive (p_input) ) )
110 msg_Dbg( p_intf, "IM: Setting an input" );
111 vlc_object_hold( p_input );
120 p_item = input_GetItem( p_input );
121 emit rateChanged( var_GetFloat( p_input, "rate" ) );
127 assert( !p_input_vbi );
128 emit rateChanged( var_InheritFloat( p_intf, "rate" ) );
132 /* delete Input if it ever existed.
133 Delete the callbacls on input
134 p_input is released once here */
135 void InputManager::delInput()
137 if( !p_input ) return;
138 msg_Dbg( p_intf, "IM: Deleting the input" );
141 i_old_playing_status = END_S;
152 vlc_object_release( p_input_vbi );
156 vlc_object_release( p_input );
159 emit positionUpdated( -1.0, 0 ,0 );
160 emit rateChanged( var_InheritFloat( p_intf, "rate" ) );
161 emit nameChanged( "" );
162 emit chapterChanged( 0 );
163 emit titleChanged( 0 );
164 emit playingStatusChanged( END_S );
166 emit teletextPossible( false );
167 emit AtoBchanged( false, false );
168 emit voutChanged( false );
169 emit voutListChanged( NULL, 0 );
171 /* Reset all InfoPanels but stats */
172 emit artChanged( NULL );
173 emit infoChanged( NULL );
174 emit currentMetaChanged( (input_item_t *)NULL );
176 emit encryptionChanged( false );
177 emit recordingStateChanged( false );
179 emit cachingChanged( 1 );
182 /* Convert the event from the callbacks in actions */
183 void InputManager::customEvent( QEvent *event )
185 int i_type = event->type();
186 IMEvent *ple = static_cast<IMEvent *>(event);
188 if( i_type == ItemChanged_Type )
189 UpdateMeta( ple->p_item );
197 case PositionUpdate_Type:
200 case StatisticsUpdate_Type:
203 case ItemChanged_Type:
204 /* Ignore ItemChanged_Type event that does not apply to our input */
205 if( p_item == ple->p_item )
210 /* Update duration of file */
213 case ItemStateChanged_Type:
214 // TODO: Fusion with above state
217 // UpdateNavigation(); This shouldn't be useful now
218 // UpdateTeletext(); Same
220 case NameChanged_Type:
223 case MetaChanged_Type:
225 UpdateName(); /* Needed for NowPlaying */
226 UpdateArt(); /* Art is part of meta in the core */
228 case InfoChanged_Type:
231 case ItemTitleChanged_Type:
233 UpdateName(); /* Display the name of the Chapter, if exists */
235 case ItemRateChanged_Type:
238 case ItemEsChanged_Type:
240 // We don't do anything ES related. Why ?
242 case ItemTeletextChanged_Type:
245 case InterfaceVoutUpdate_Type:
248 case SynchroChanged_Type:
249 emit synchroChanged();
251 case CachingEvent_Type:
254 case BookmarksChanged_Type:
255 emit bookmarksChanged();
257 case InterfaceAoutUpdate_Type:
260 case RecordingEvent_Type:
263 case ProgramChanged_Type:
264 UpdateProgramEvent();
270 msg_Warn( p_intf, "This shouldn't happen: %i", i_type );
275 /* Add the callbacks on Input. Self explanatory */
276 inline void InputManager::addCallbacks()
278 var_AddCallback( p_input, "intf-event", InputEvent, this );
281 /* Delete the callbacks on Input. Self explanatory */
282 inline void InputManager::delCallbacks()
284 var_DelCallback( p_input, "intf-event", InputEvent, this );
287 /* Static callbacks for IM */
288 static int ItemChanged( vlc_object_t *p_this, const char *psz_var,
289 vlc_value_t oldval, vlc_value_t newval, void *param )
291 VLC_UNUSED( p_this ); VLC_UNUSED( psz_var ); VLC_UNUSED( oldval );
293 InputManager *im = (InputManager*)param;
294 input_item_t *p_item = static_cast<input_item_t *>(newval.p_address);
296 IMEvent *event = new IMEvent( ItemChanged_Type, p_item );
297 QApplication::postEvent( im, event );
301 static int InputEvent( vlc_object_t *p_this, const char *,
302 vlc_value_t, vlc_value_t newval, void *param )
304 VLC_UNUSED( p_this );
306 InputManager *im = (InputManager*)param;
309 switch( newval.i_int )
311 case INPUT_EVENT_STATE:
312 event = new IMEvent( ItemStateChanged_Type );
314 case INPUT_EVENT_RATE:
315 event = new IMEvent( ItemRateChanged_Type );
317 case INPUT_EVENT_POSITION:
318 //case INPUT_EVENT_LENGTH:
319 event = new IMEvent( PositionUpdate_Type );
322 case INPUT_EVENT_TITLE:
323 case INPUT_EVENT_CHAPTER:
324 event = new IMEvent( ItemTitleChanged_Type );
328 event = new IMEvent( ItemEsChanged_Type );
330 case INPUT_EVENT_TELETEXT:
331 event = new IMEvent( ItemTeletextChanged_Type );
334 case INPUT_EVENT_STATISTICS:
335 event = new IMEvent( StatisticsUpdate_Type );
338 case INPUT_EVENT_VOUT:
339 event = new IMEvent( InterfaceVoutUpdate_Type );
341 case INPUT_EVENT_AOUT:
342 event = new IMEvent( InterfaceAoutUpdate_Type );
345 case INPUT_EVENT_ITEM_META: /* Codec MetaData + Art */
346 event = new IMEvent( MetaChanged_Type );
348 case INPUT_EVENT_ITEM_INFO: /* Codec Info */
349 event = new IMEvent( InfoChanged_Type );
351 case INPUT_EVENT_ITEM_NAME:
352 event = new IMEvent( NameChanged_Type );
355 case INPUT_EVENT_AUDIO_DELAY:
356 case INPUT_EVENT_SUBTITLE_DELAY:
357 event = new IMEvent( SynchroChanged_Type );
360 case INPUT_EVENT_CACHE:
361 event = new IMEvent( CachingEvent_Type );
364 case INPUT_EVENT_BOOKMARK:
365 event = new IMEvent( BookmarksChanged_Type );
368 case INPUT_EVENT_RECORD:
369 event = new IMEvent( RecordingEvent_Type );
372 case INPUT_EVENT_PROGRAM:
373 /* This is for PID changes */
374 event = new IMEvent( ProgramChanged_Type );
377 case INPUT_EVENT_ITEM_EPG:
378 /* EPG data changed */
379 event = new IMEvent( EPGEvent_Type );
382 case INPUT_EVENT_SIGNAL:
383 /* This is for capture-card signals */
384 /* event = new IMEvent( SignalChanged_Type );
392 QApplication::postEvent( im, event );
396 static int VbiEvent( vlc_object_t *, const char *,
397 vlc_value_t, vlc_value_t, void *param )
399 InputManager *im = (InputManager*)param;
400 IMEvent *event = new IMEvent( ItemTeletextChanged_Type );
402 QApplication::postEvent( im, event );
406 void InputManager::UpdatePosition()
408 /* Update position */
412 i_length = var_GetTime( p_input , "length" ) / CLOCK_FREQ;
413 i_time = var_GetTime( p_input , "time");
414 f_pos = var_GetFloat( p_input , "position" );
415 emit positionUpdated( f_pos, i_time, i_length );
418 void InputManager::UpdateNavigation()
420 /* Update navigation status */
421 vlc_value_t val; val.i_int = 0;
422 vlc_value_t val2; val2.i_int = 0;
425 var_Change( p_input, "title", VLC_VAR_CHOICESCOUNT, &val, NULL );
429 emit titleChanged( true );
430 msg_Dbg( p_intf, "Title %"PRId64, val.i_int );
431 /* p_input != NULL since val.i_int != 0 */
432 var_Change( p_input, "chapter", VLC_VAR_CHOICESCOUNT, &val2, NULL );
433 emit chapterChanged( (val2.i_int > 1) || ( val2.i_int > 0 && val.i_int > 1 ) );
434 msg_Dbg( p_intf, "Chapter: %"PRId64, val2.i_int );
437 emit titleChanged( false );
440 void InputManager::UpdateStatus()
442 /* Update playing status */
443 int state = var_GetInteger( p_input, "state" );
444 if( i_old_playing_status != state )
446 i_old_playing_status = state;
447 emit playingStatusChanged( state );
451 void InputManager::UpdateRate()
454 float f_new_rate = var_GetFloat( p_input, "rate" );
455 if( f_new_rate != f_rate )
459 emit rateChanged( f_rate );
463 void InputManager::UpdateName()
467 /* Update text, name and nowplaying */
470 /* Try to get the nowplaying */
471 char *format = var_InheritString( p_intf, "input-title-format" );
472 char *formated = str_format_meta( p_input, format );
474 name = qfu(formated);
477 /* If we have Nothing */
480 char *uri = input_item_GetURI( input_GetItem( p_input ) );
481 char *file = uri ? strrchr( uri, '/' ) : NULL;
484 decode_URI( ++file );
492 name = name.trimmed();
494 if( oldName != name )
496 emit nameChanged( name );
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 bool InputManager::hasVisualisation()
522 audio_output_t *aout = input_GetAout( p_input );
526 char *visual = var_InheritString( aout, "visual" );
527 vlc_object_release( aout );
536 void InputManager::UpdateTeletext()
540 const bool b_enabled = var_CountChoices( p_input, "teletext-es" ) > 0;
541 const int i_teletext_es = var_GetInteger( p_input, "teletext-es" );
543 /* Teletext is possible. Show the buttons */
544 emit teletextPossible( b_enabled );
546 /* If Teletext is selected */
547 if( b_enabled && i_teletext_es >= 0 )
549 /* Then, find the current page */
551 bool b_transparent = false;
555 var_DelCallback( p_input_vbi, "vbi-page", VbiEvent, this );
556 vlc_object_release( p_input_vbi );
559 if( input_GetEsObjects( p_input, i_teletext_es, &p_input_vbi, NULL, NULL ) )
564 /* This callback is not remove explicitly, but interfaces
565 * are guaranted to outlive input */
566 var_AddCallback( p_input_vbi, "vbi-page", VbiEvent, this );
568 i_page = var_GetInteger( p_input_vbi, "vbi-page" );
569 b_transparent = !var_GetBool( p_input_vbi, "vbi-opaque" );
571 emit newTelexPageSet( i_page );
572 emit teletextTransparencyActivated( b_transparent );
575 emit teletextActivated( b_enabled && i_teletext_es >= 0 );
579 emit teletextActivated( false );
580 emit teletextPossible( false );
584 void InputManager::UpdateEPG()
592 void InputManager::UpdateVout()
596 /* Get current vout lists from input */
598 vout_thread_t **pp_vout;
599 if( input_Control( p_input, INPUT_GET_VOUTS, &pp_vout, &i_vout ) )
606 emit voutListChanged( pp_vout, i_vout );
609 bool b_old_video = b_video;
610 b_video = i_vout > 0;
611 if( !!b_old_video != !!b_video )
612 emit voutChanged( b_video );
614 /* Release the vout list */
615 for( size_t i = 0; i < i_vout; i++ )
616 vlc_object_release( (vlc_object_t*)pp_vout[i] );
620 void InputManager::UpdateAout()
627 void InputManager::UpdateCaching()
629 if(!hasInput()) return;
631 float f_newCache = var_GetFloat ( p_input, "cache" );
632 if( f_newCache != f_cache )
634 f_cache = f_newCache;
636 emit cachingChanged( f_cache );
640 void InputManager::requestArtUpdate()
644 playlist_AskForArtEnqueue( pl_Get(p_intf), input_GetItem( p_input ) );
648 /* No input will signal the cover art to update,
649 * let's do it ourself */
654 const QString InputManager::decodeArtURL( input_item_t *p_item )
658 char *psz_art = input_item_GetArtURL( p_item );
661 char *psz = make_path( psz_art );
667 /* Taglib seems to define a attachment://, It won't work yet */
668 url = url.replace( "attachment://", "" );
671 QString path = qfu( psz_art ? psz_art : "" );
676 void InputManager::UpdateArt()
681 url = decodeArtURL( input_GetItem( p_input ) );
683 /* the art hasn't changed, no need to update */
687 /* Update Art meta */
689 emit artChanged( artUrl );
692 inline void InputManager::UpdateStats()
695 emit statisticsUpdated( input_GetItem( p_input ) );
698 inline void InputManager::UpdateMeta( input_item_t *p_item )
700 emit metaChanged( p_item );
703 inline void InputManager::UpdateMeta()
706 emit currentMetaChanged( input_GetItem( p_input ) );
709 inline void InputManager::UpdateInfo()
712 emit infoChanged( input_GetItem( p_input ) );
715 void InputManager::UpdateRecord()
719 emit recordingStateChanged( var_GetBool( p_input, "record" ) );
723 void InputManager::UpdateProgramEvent()
727 bool b_scrambled = var_GetBool( p_input, "program-scrambled" );
728 emit encryptionChanged( b_scrambled );
732 /* User update of the slider */
733 void InputManager::sliderUpdate( float new_pos )
736 var_SetFloat( p_input, "position", new_pos );
737 emit seekRequested( new_pos );
740 /* User togglePlayPause */
741 void InputManager::togglePlayPause()
745 int state = var_GetInteger( p_input, "state" );
746 state = ( state != PLAYING_S ) ? PLAYING_S : PAUSE_S;
747 var_SetInteger( p_input, "state", state );
751 void InputManager::sectionPrev()
755 int i_type = var_Type( p_input, "next-chapter" );
756 var_TriggerCallback( p_input, (i_type & VLC_VAR_TYPE) != 0 ?
757 "prev-chapter":"prev-title" );
761 void InputManager::sectionNext()
765 int i_type = var_Type( p_input, "next-chapter" );
766 var_TriggerCallback( p_input, (i_type & VLC_VAR_TYPE) != 0 ?
767 "next-chapter":"next-title" );
771 void InputManager::sectionMenu()
775 vlc_value_t val, text;
777 if( var_Change( p_input, "title 0", VLC_VAR_GETLIST, &val, &text ) < 0 )
780 /* XXX is it "Root" or "Title" we want here ?" (set 0 by default) */
782 for( int i = 0; i < val.p_list->i_count; i++ )
784 if( !strcmp( text.p_list->p_values[i].psz_string, "Title" ) )
787 var_FreeList( &val, &text );
789 var_SetInteger( p_input, "title 0", root );
797 /* Set a new Teletext Page */
798 void InputManager::telexSetPage( int page )
800 if( hasInput() && p_input_vbi )
802 const int i_teletext_es = var_GetInteger( p_input, "teletext-es" );
804 if( i_teletext_es >= 0 )
806 var_SetInteger( p_input_vbi, "vbi-page", page );
807 emit newTelexPageSet( page );
812 /* Set the transparency on teletext */
813 void InputManager::telexSetTransparency( bool b_transparentTelextext )
815 if( hasInput() && p_input_vbi )
817 var_SetBool( p_input_vbi, "vbi-opaque", !b_transparentTelextext );
818 emit teletextTransparencyActivated( b_transparentTelextext );
822 void InputManager::activateTeletext( bool b_enable )
826 if( hasInput() && !var_Change( p_input, "teletext-es", VLC_VAR_GETLIST, &list, &text ) )
828 if( list.p_list->i_count > 0 )
830 /* Prefer the page 100 if it is present */
832 for( i = 0; i < text.p_list->i_count; i++ )
834 /* The description is the page number as a string */
835 const char *psz_page = text.p_list->p_values[i].psz_string;
836 if( psz_page && !strcmp( psz_page, "100" ) )
839 if( i >= list.p_list->i_count )
841 var_SetInteger( p_input, "spu-es", b_enable ? list.p_list->p_values[i].i_int : -1 );
843 var_FreeList( &list, &text );
847 void InputManager::reverse()
851 float f_rate = var_GetFloat( p_input, "rate" );
852 var_SetFloat( p_input, "rate", -f_rate );
856 void InputManager::slower()
858 var_TriggerCallback( THEPL, "rate-slower" );
861 void InputManager::faster()
863 var_TriggerCallback( THEPL, "rate-faster" );
866 void InputManager::littlefaster()
868 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_RATE_FASTER_FINE );
871 void InputManager::littleslower()
873 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_RATE_SLOWER_FINE );
876 void InputManager::normalRate()
878 var_SetFloat( THEPL, "rate", 1. );
881 void InputManager::setRate( int new_rate )
883 var_SetFloat( THEPL, "rate",
884 (float)INPUT_RATE_DEFAULT / (float)new_rate );
887 void InputManager::jumpFwd()
889 int i_interval = var_InheritInteger( p_input, "short-jump-size" );
890 if( i_interval > 0 && hasInput() )
892 mtime_t val = CLOCK_FREQ * i_interval;
893 var_SetTime( p_input, "time-offset", val );
897 void InputManager::jumpBwd()
899 int i_interval = var_InheritInteger( p_input, "short-jump-size" );
900 if( i_interval > 0 && hasInput() )
902 mtime_t val = -CLOCK_FREQ * i_interval;
903 var_SetTime( p_input, "time-offset", val );
907 void InputManager::setAtoB()
911 timeA = var_GetTime( THEMIM->getInput(), "time" );
915 timeB = var_GetTime( THEMIM->getInput(), "time" );
916 var_SetTime( THEMIM->getInput(), "time" , timeA );
917 CONNECT( this, positionUpdated( float, int64_t, int ),
918 this, AtoBLoop( float, int64_t, int ) );
924 disconnect( this, SIGNAL( positionUpdated( float, int64_t, int ) ),
925 this, SLOT( AtoBLoop( float, int64_t, int ) ) );
927 emit AtoBchanged( (timeA != 0 ), (timeB != 0 ) );
930 /* Function called regularly when in an AtoB loop */
931 void InputManager::AtoBLoop( float, int64_t i_time, int )
935 if( i_time >= timeB || i_time < timeA )
936 var_SetTime( THEMIM->getInput(), "time" , timeA );
940 /**********************************************************************
941 * MainInputManager implementation. Wrap an input manager and
942 * take care of updating the main playlist input.
943 * Used in the main playlist Dialog
944 **********************************************************************/
946 MainInputManager::MainInputManager( intf_thread_t *_p_intf )
947 : QObject(NULL), p_intf( _p_intf )
950 im = new InputManager( this, p_intf );
952 var_AddCallback( THEPL, "item-change", ItemChanged, im );
953 var_AddCallback( THEPL, "item-current", PLItemChanged, this );
954 var_AddCallback( THEPL, "activity", PLItemChanged, this );
955 var_AddCallback( THEPL, "leaf-to-parent", LeafToParent, this );
956 var_AddCallback( THEPL, "playlist-item-append", PLItemAppended, this );
957 var_AddCallback( THEPL, "playlist-item-deleted", PLItemRemoved, this );
958 var_AddCallback( THEPL, "random", RandomChanged, this );
959 var_AddCallback( THEPL, "repeat", RepeatChanged, this );
960 var_AddCallback( THEPL, "loop", LoopChanged, this );
962 var_AddCallback( THEPL, "volume", VolumeChanged, this );
963 var_AddCallback( THEPL, "mute", SoundMuteChanged, this );
965 /* Warn our embedded IM about input changes */
966 DCONNECT( this, inputChanged( input_thread_t * ),
967 im, setInput( input_thread_t * ) );
971 MainInputManager::~MainInputManager()
975 emit inputChanged( NULL );
976 var_DelCallback( p_input, "state", PLItemChanged, this );
977 vlc_object_release( p_input );
980 var_DelCallback( THEPL, "volume", VolumeChanged, this );
981 var_DelCallback( THEPL, "mute", SoundMuteChanged, this );
983 var_DelCallback( THEPL, "activity", PLItemChanged, this );
984 var_DelCallback( THEPL, "item-change", ItemChanged, im );
985 var_DelCallback( THEPL, "leaf-to-parent", LeafToParent, this );
987 var_DelCallback( THEPL, "item-current", PLItemChanged, this );
988 var_DelCallback( THEPL, "playlist-item-append", PLItemAppended, this );
989 var_DelCallback( THEPL, "playlist-item-deleted", PLItemRemoved, this );
990 var_DelCallback( THEPL, "random", RandomChanged, this );
991 var_DelCallback( THEPL, "repeat", RepeatChanged, this );
992 var_DelCallback( THEPL, "loop", LoopChanged, this );
994 /* Save some interface state in configuration, at module quit */
995 config_PutInt( p_intf, "random", var_GetBool( THEPL, "random" ) );
996 config_PutInt( p_intf, "loop", var_GetBool( THEPL, "loop" ) );
997 config_PutInt( p_intf, "repeat", var_GetBool( THEPL, "repeat" ) );
999 if( var_InheritBool( p_intf, "qt-autosave-volume" ) )
1000 config_PutInt( p_intf, "volume", aout_VolumeGet( THEPL ) );
1003 vout_thread_t* MainInputManager::getVout()
1005 return p_input ? input_GetVout( p_input ) : NULL;
1008 audio_output_t * MainInputManager::getAout()
1010 return p_input ? input_GetAout( p_input ) : NULL;
1013 void MainInputManager::customEvent( QEvent *event )
1015 int type = event->type();
1019 // msg_Dbg( p_intf, "New MainIM Event of type: %i", type );
1022 case VolumeChanged_Type:
1023 emit volumeChanged();
1025 case SoundMuteChanged_Type:
1026 emit soundMuteChanged();
1028 case PLItemAppended_Type:
1029 plEv = static_cast<PLEvent*>( event );
1030 emit playlistItemAppended( plEv->i_item, plEv->i_parent );
1032 case PLItemRemoved_Type:
1033 plEv = static_cast<PLEvent*>( event );
1034 emit playlistItemRemoved( plEv->i_item );
1036 case RandomChanged_Type:
1037 emit randomChanged( var_GetBool( THEPL, "random" ) );
1039 case LoopChanged_Type:
1040 case RepeatChanged_Type:
1043 case LeafToParent_Type:
1044 plEv = static_cast<PLEvent*>( event );
1045 emit leafBecameParent( plEv->i_item );
1048 if( type != ItemChanged_Type ) return;
1051 /* Should be PLItemChanged Event */
1052 if( !p_intf->p_sys->b_isDialogProvider )
1054 if( p_input && ( p_input->b_dead || !vlc_object_alive (p_input) ) )
1056 emit inputChanged( p_input );
1057 var_DelCallback( p_input, "state", PLItemChanged, this );
1058 vlc_object_release( p_input );
1065 p_input = playlist_CurrentInput(THEPL);
1068 var_AddCallback( p_input, "state", PLItemChanged, this );
1069 emit inputChanged( p_input );
1075 /* remove previous stored p_input */
1078 vlc_object_release( p_input );
1081 /* we are working as a dialogs provider */
1082 p_input = playlist_CurrentInput( pl_Get(p_intf) );
1085 emit inputChanged( p_input );
1090 /* Playlist Control functions */
1091 void MainInputManager::stop()
1093 playlist_Stop( THEPL );
1096 void MainInputManager::next()
1098 playlist_Next( THEPL );
1101 void MainInputManager::prev()
1103 playlist_Prev( THEPL );
1106 void MainInputManager::prevOrReset()
1108 if( !p_input || var_GetTime( p_input , "time") < 10000 )
1109 playlist_Prev( THEPL );
1111 getIM()->sliderUpdate( 0.0 );
1114 void MainInputManager::togglePlayPause()
1116 /* No input, play */
1118 playlist_Play( THEPL );
1120 getIM()->togglePlayPause();
1123 void MainInputManager::play()
1125 /* No input, play */
1127 playlist_Play( THEPL );
1130 if( PLAYING_S != var_GetInteger( p_input, "state" ) )
1132 getIM()->togglePlayPause();
1137 void MainInputManager::pause()
1139 if(p_input && PLAYING_S == var_GetInteger( p_input, "state" ) )
1141 getIM()->togglePlayPause();
1145 void MainInputManager::toggleRandom()
1147 var_ToggleBool( THEPL, "random" );
1150 void MainInputManager::notifyRepeatLoop()
1152 int i_value = var_GetBool( THEPL, "loop" ) * REPEAT_ALL
1153 + var_GetBool( THEPL, "repeat" ) * REPEAT_ONE;
1155 emit repeatLoopChanged( i_value );
1158 void MainInputManager::loopRepeatLoopStatus()
1160 /* Toggle Normal -> Loop -> Repeat -> Normal ... */
1161 if( var_GetBool( THEPL, "repeat" ) )
1162 var_SetBool( THEPL, "repeat", false );
1163 else if( var_GetBool( THEPL, "loop" ) )
1165 var_SetBool( THEPL, "loop", false );
1166 var_SetBool( THEPL, "repeat", true );
1169 var_SetBool( THEPL, "loop", true );
1172 void MainInputManager::activatePlayQuit( bool b_exit )
1174 var_SetBool( THEPL, "play-and-exit", b_exit );
1177 bool MainInputManager::getPlayExitState()
1179 return var_GetBool( THEPL, "play-and-exit" );
1182 /****************************
1183 * Static callbacks for MIM *
1184 ****************************/
1185 static int PLItemChanged( vlc_object_t *p_this, const char *psz_var,
1186 vlc_value_t oldval, vlc_value_t, void *param )
1188 VLC_UNUSED( p_this ); VLC_UNUSED( psz_var ); VLC_UNUSED( oldval );
1190 MainInputManager *mim = (MainInputManager*)param;
1192 IMEvent *event = new IMEvent( ItemChanged_Type );
1193 QApplication::postEvent( mim, event );
1197 static int LeafToParent( vlc_object_t *p_this, const char *psz_var,
1198 vlc_value_t oldval, vlc_value_t newval, void *param )
1200 VLC_UNUSED( p_this ); VLC_UNUSED( psz_var ); VLC_UNUSED( oldval );
1201 MainInputManager *mim = (MainInputManager*)param;
1203 PLEvent *event = new PLEvent( LeafToParent_Type, newval.i_int );
1205 QApplication::postEvent( mim, event );
1209 static int VolumeChanged( vlc_object_t *p_this, const char *psz_var,
1210 vlc_value_t oldval, vlc_value_t newval, void *param )
1212 VLC_UNUSED( p_this ); VLC_UNUSED( psz_var ); VLC_UNUSED( oldval ); VLC_UNUSED( newval );
1214 MainInputManager *mim = (MainInputManager*)param;
1216 IMEvent *event = new IMEvent( VolumeChanged_Type );
1217 QApplication::postEvent( mim, event );
1221 static int SoundMuteChanged( vlc_object_t *p_this, const char *psz_var,
1222 vlc_value_t oldval, vlc_value_t newval, void *param )
1224 VLC_UNUSED( p_this ); VLC_UNUSED( psz_var ); VLC_UNUSED( oldval ); VLC_UNUSED( newval );
1226 MainInputManager *mim = (MainInputManager*)param;
1228 IMEvent *event = new IMEvent( SoundMuteChanged_Type );
1229 QApplication::postEvent( mim, event );
1233 static int PLItemAppended
1234 ( vlc_object_t * obj, const char *var, vlc_value_t old, vlc_value_t cur, void *data )
1236 VLC_UNUSED( obj ); VLC_UNUSED( var ); VLC_UNUSED( old );
1238 MainInputManager *mim = static_cast<MainInputManager*>(data);
1239 playlist_add_t *p_add = static_cast<playlist_add_t*>( cur.p_address );
1241 PLEvent *event = new PLEvent( PLItemAppended_Type, p_add->i_item, p_add->i_node );
1242 QApplication::postEvent( mim, event );
1245 static int PLItemRemoved
1246 ( vlc_object_t * obj, const char *var, vlc_value_t old, vlc_value_t cur, void *data )
1248 VLC_UNUSED( obj ); VLC_UNUSED( var ); VLC_UNUSED( old );
1250 MainInputManager *mim = static_cast<MainInputManager*>(data);
1252 PLEvent *event = new PLEvent( PLItemRemoved_Type, cur.i_int, 0 );
1253 QApplication::postEvent( mim, event );
1257 static int RandomChanged
1258 ( vlc_object_t * obj, const char *var, vlc_value_t old, vlc_value_t cur, void *data )
1260 VLC_UNUSED( obj ); VLC_UNUSED( var ); VLC_UNUSED( old ); VLC_UNUSED( cur );
1262 MainInputManager *mim = static_cast<MainInputManager*>(data);
1264 IMEvent *event = new IMEvent( RandomChanged_Type );
1265 QApplication::postEvent( mim, event );
1269 /* Probably could be merged with next callback */
1270 static int LoopChanged
1271 ( vlc_object_t * obj, const char *var, vlc_value_t old, vlc_value_t cur, void *data )
1273 VLC_UNUSED( obj ); VLC_UNUSED( var ); VLC_UNUSED( old ); VLC_UNUSED( cur );
1275 MainInputManager *mim = static_cast<MainInputManager*>(data);
1277 IMEvent *event = new IMEvent( LoopChanged_Type );
1278 QApplication::postEvent( mim, event );
1282 static int RepeatChanged
1283 ( vlc_object_t * obj, const char *var, vlc_value_t old, vlc_value_t cur, void *data )
1285 VLC_UNUSED( obj ); VLC_UNUSED( var ); VLC_UNUSED( old ); VLC_UNUSED( cur );
1287 MainInputManager *mim = static_cast<MainInputManager*>(data);
1289 IMEvent *event = new IMEvent( RepeatChanged_Type );
1290 QApplication::postEvent( mim, event );