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()
465 /* Update text, name and nowplaying */
468 /* Try to get the nowplaying */
469 char *format = var_InheritString( p_intf, "input-title-format" );
470 char *formated = str_format_meta( p_input, format );
472 name = qfu(formated);
475 /* If we have Nothing */
478 char *uri = input_item_GetURI( input_GetItem( p_input ) );
479 char *file = uri ? strrchr( uri, '/' ) : NULL;
482 decode_URI( ++file );
490 name = name.trimmed();
492 if( oldName != name )
494 emit nameChanged( name );
499 int InputManager::playingStatus()
501 return i_old_playing_status;
504 bool InputManager::hasAudio()
509 var_Change( p_input, "audio-es", VLC_VAR_CHOICESCOUNT, &val, NULL );
510 return val.i_int > 0;
515 bool InputManager::hasVisualisation()
520 audio_output_t *aout = input_GetAout( p_input );
524 char *visual = var_InheritString( aout, "visual" );
525 vlc_object_release( aout );
534 void InputManager::UpdateTeletext()
538 const bool b_enabled = var_CountChoices( p_input, "teletext-es" ) > 0;
539 const int i_teletext_es = var_GetInteger( p_input, "teletext-es" );
541 /* Teletext is possible. Show the buttons */
542 emit teletextPossible( b_enabled );
544 /* If Teletext is selected */
545 if( b_enabled && i_teletext_es >= 0 )
547 /* Then, find the current page */
549 bool b_transparent = false;
553 var_DelCallback( p_input_vbi, "vbi-page", VbiEvent, this );
554 vlc_object_release( p_input_vbi );
557 if( input_GetEsObjects( p_input, i_teletext_es, &p_input_vbi, NULL, NULL ) )
562 /* This callback is not remove explicitly, but interfaces
563 * are guaranted to outlive input */
564 var_AddCallback( p_input_vbi, "vbi-page", VbiEvent, this );
566 i_page = var_GetInteger( p_input_vbi, "vbi-page" );
567 b_transparent = !var_GetBool( p_input_vbi, "vbi-opaque" );
569 emit newTelexPageSet( i_page );
570 emit teletextTransparencyActivated( b_transparent );
573 emit teletextActivated( b_enabled && i_teletext_es >= 0 );
577 emit teletextActivated( false );
578 emit teletextPossible( false );
582 void InputManager::UpdateEPG()
590 void InputManager::UpdateVout()
594 /* Get current vout lists from input */
596 vout_thread_t **pp_vout;
597 if( input_Control( p_input, INPUT_GET_VOUTS, &pp_vout, &i_vout ) )
604 emit voutListChanged( pp_vout, i_vout );
607 bool b_old_video = b_video;
608 b_video = i_vout > 0;
609 if( !!b_old_video != !!b_video )
610 emit voutChanged( b_video );
612 /* Release the vout list */
613 for( size_t i = 0; i < i_vout; i++ )
614 vlc_object_release( (vlc_object_t*)pp_vout[i] );
618 void InputManager::UpdateAout()
625 void InputManager::UpdateCaching()
627 if(!hasInput()) return;
629 float f_newCache = var_GetFloat ( p_input, "cache" );
630 if( f_newCache != f_cache )
632 f_cache = f_newCache;
634 emit cachingChanged( f_cache );
638 void InputManager::requestArtUpdate()
642 playlist_AskForArtEnqueue( pl_Get(p_intf), input_GetItem( p_input ) );
646 /* No input will signal the cover art to update,
647 * let's do it ourself */
652 const QString InputManager::decodeArtURL( input_item_t *p_item )
656 char *psz_art = input_item_GetArtURL( p_item );
659 char *psz = make_path( psz_art );
665 /* Taglib seems to define a attachment://, It won't work yet */
666 url = url.replace( "attachment://", "" );
669 QString path = qfu( psz_art ? psz_art : "" );
674 void InputManager::UpdateArt()
679 url = decodeArtURL( input_GetItem( p_input ) );
681 /* the art hasn't changed, no need to update */
685 /* Update Art meta */
687 emit artChanged( artUrl );
690 inline void InputManager::UpdateStats()
692 emit statisticsUpdated( input_GetItem( p_input ) );
695 inline void InputManager::UpdateMeta( input_item_t *p_item )
697 emit metaChanged( p_item );
700 inline void InputManager::UpdateMeta()
702 emit currentMetaChanged( input_GetItem( p_input ) );
705 inline void InputManager::UpdateInfo()
707 emit infoChanged( input_GetItem( p_input ) );
710 void InputManager::UpdateRecord()
714 emit recordingStateChanged( var_GetBool( p_input, "record" ) );
718 void InputManager::UpdateProgramEvent()
722 bool b_scrambled = var_GetBool( p_input, "program-scrambled" );
723 emit encryptionChanged( b_scrambled );
727 /* User update of the slider */
728 void InputManager::sliderUpdate( float new_pos )
731 var_SetFloat( p_input, "position", new_pos );
732 emit seekRequested( new_pos );
735 /* User togglePlayPause */
736 void InputManager::togglePlayPause()
740 int state = var_GetInteger( p_input, "state" );
741 state = ( state != PLAYING_S ) ? PLAYING_S : PAUSE_S;
742 var_SetInteger( p_input, "state", state );
746 void InputManager::sectionPrev()
750 int i_type = var_Type( p_input, "next-chapter" );
751 var_TriggerCallback( p_input, (i_type & VLC_VAR_TYPE) != 0 ?
752 "prev-chapter":"prev-title" );
756 void InputManager::sectionNext()
760 int i_type = var_Type( p_input, "next-chapter" );
761 var_TriggerCallback( p_input, (i_type & VLC_VAR_TYPE) != 0 ?
762 "next-chapter":"next-title" );
766 void InputManager::sectionMenu()
770 vlc_value_t val, text;
772 if( var_Change( p_input, "title 0", VLC_VAR_GETLIST, &val, &text ) < 0 )
775 /* XXX is it "Root" or "Title" we want here ?" (set 0 by default) */
777 for( int i = 0; i < val.p_list->i_count; i++ )
779 if( !strcmp( text.p_list->p_values[i].psz_string, "Title" ) )
782 var_FreeList( &val, &text );
784 var_SetInteger( p_input, "title 0", root );
792 /* Set a new Teletext Page */
793 void InputManager::telexSetPage( int page )
795 if( hasInput() && p_input_vbi )
797 const int i_teletext_es = var_GetInteger( p_input, "teletext-es" );
799 if( i_teletext_es >= 0 )
801 var_SetInteger( p_input_vbi, "vbi-page", page );
802 emit newTelexPageSet( page );
807 /* Set the transparency on teletext */
808 void InputManager::telexSetTransparency( bool b_transparentTelextext )
810 if( hasInput() && p_input_vbi )
812 var_SetBool( p_input_vbi, "vbi-opaque", !b_transparentTelextext );
813 emit teletextTransparencyActivated( b_transparentTelextext );
817 void InputManager::activateTeletext( bool b_enable )
821 if( hasInput() && !var_Change( p_input, "teletext-es", VLC_VAR_GETLIST, &list, &text ) )
823 if( list.p_list->i_count > 0 )
825 /* Prefer the page 100 if it is present */
827 for( i = 0; i < text.p_list->i_count; i++ )
829 /* The description is the page number as a string */
830 const char *psz_page = text.p_list->p_values[i].psz_string;
831 if( psz_page && !strcmp( psz_page, "100" ) )
834 if( i >= list.p_list->i_count )
836 var_SetInteger( p_input, "spu-es", b_enable ? list.p_list->p_values[i].i_int : -1 );
838 var_FreeList( &list, &text );
842 void InputManager::reverse()
846 float f_rate = var_GetFloat( p_input, "rate" );
847 var_SetFloat( p_input, "rate", -f_rate );
851 void InputManager::slower()
853 var_TriggerCallback( THEPL, "rate-slower" );
856 void InputManager::faster()
858 var_TriggerCallback( THEPL, "rate-faster" );
861 void InputManager::littlefaster()
863 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_RATE_FASTER_FINE );
866 void InputManager::littleslower()
868 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_RATE_SLOWER_FINE );
871 void InputManager::normalRate()
873 var_SetFloat( THEPL, "rate", 1. );
876 void InputManager::setRate( int new_rate )
878 var_SetFloat( THEPL, "rate",
879 (float)INPUT_RATE_DEFAULT / (float)new_rate );
882 void InputManager::jumpFwd()
884 int i_interval = var_InheritInteger( p_input, "short-jump-size" );
885 if( i_interval > 0 && hasInput() )
887 mtime_t val = CLOCK_FREQ * i_interval;
888 var_SetTime( p_input, "time-offset", val );
892 void InputManager::jumpBwd()
894 int i_interval = var_InheritInteger( p_input, "short-jump-size" );
895 if( i_interval > 0 && hasInput() )
897 mtime_t val = -CLOCK_FREQ * i_interval;
898 var_SetTime( p_input, "time-offset", val );
902 void InputManager::setAtoB()
906 timeA = var_GetTime( THEMIM->getInput(), "time" );
910 timeB = var_GetTime( THEMIM->getInput(), "time" );
911 var_SetTime( THEMIM->getInput(), "time" , timeA );
912 CONNECT( this, positionUpdated( float, int64_t, int ),
913 this, AtoBLoop( float, int64_t, int ) );
919 disconnect( this, SIGNAL( positionUpdated( float, int64_t, int ) ),
920 this, SLOT( AtoBLoop( float, int64_t, int ) ) );
922 emit AtoBchanged( (timeA != 0 ), (timeB != 0 ) );
925 /* Function called regularly when in an AtoB loop */
926 void InputManager::AtoBLoop( float, int64_t i_time, int )
930 if( i_time >= timeB || i_time < timeA )
931 var_SetTime( THEMIM->getInput(), "time" , timeA );
935 /**********************************************************************
936 * MainInputManager implementation. Wrap an input manager and
937 * take care of updating the main playlist input.
938 * Used in the main playlist Dialog
939 **********************************************************************/
941 MainInputManager::MainInputManager( intf_thread_t *_p_intf )
942 : QObject(NULL), p_intf( _p_intf )
945 im = new InputManager( this, p_intf );
947 var_AddCallback( THEPL, "item-change", ItemChanged, im );
948 var_AddCallback( THEPL, "item-current", PLItemChanged, this );
949 var_AddCallback( THEPL, "activity", PLItemChanged, this );
950 var_AddCallback( THEPL, "leaf-to-parent", LeafToParent, this );
951 var_AddCallback( THEPL, "playlist-item-append", PLItemAppended, this );
952 var_AddCallback( THEPL, "playlist-item-deleted", PLItemRemoved, this );
953 var_AddCallback( THEPL, "random", RandomChanged, this );
954 var_AddCallback( THEPL, "repeat", RepeatChanged, this );
955 var_AddCallback( THEPL, "loop", LoopChanged, this );
957 var_AddCallback( THEPL, "volume", VolumeChanged, this );
958 var_AddCallback( THEPL, "mute", SoundMuteChanged, this );
960 /* Warn our embedded IM about input changes */
961 DCONNECT( this, inputChanged( input_thread_t * ),
962 im, setInput( input_thread_t * ) );
966 MainInputManager::~MainInputManager()
970 emit inputChanged( NULL );
971 var_DelCallback( p_input, "state", PLItemChanged, this );
972 vlc_object_release( p_input );
975 var_DelCallback( THEPL, "volume", VolumeChanged, this );
976 var_DelCallback( THEPL, "mute", SoundMuteChanged, this );
978 var_DelCallback( THEPL, "activity", PLItemChanged, this );
979 var_DelCallback( THEPL, "item-change", ItemChanged, im );
980 var_DelCallback( THEPL, "leaf-to-parent", LeafToParent, this );
982 var_DelCallback( THEPL, "item-current", PLItemChanged, this );
983 var_DelCallback( THEPL, "playlist-item-append", PLItemAppended, this );
984 var_DelCallback( THEPL, "playlist-item-deleted", PLItemRemoved, this );
985 var_DelCallback( THEPL, "random", RandomChanged, this );
986 var_DelCallback( THEPL, "repeat", RepeatChanged, this );
987 var_DelCallback( THEPL, "loop", LoopChanged, this );
989 /* Save some interface state in configuration, at module quit */
990 config_PutInt( p_intf, "random", var_GetBool( THEPL, "random" ) );
991 config_PutInt( p_intf, "loop", var_GetBool( THEPL, "loop" ) );
992 config_PutInt( p_intf, "repeat", var_GetBool( THEPL, "repeat" ) );
994 if( var_InheritBool( p_intf, "qt-autosave-volume" ) )
995 config_PutInt( p_intf, "volume", aout_VolumeGet( THEPL ) );
998 vout_thread_t* MainInputManager::getVout()
1000 return p_input ? input_GetVout( p_input ) : NULL;
1003 audio_output_t * MainInputManager::getAout()
1005 return p_input ? input_GetAout( p_input ) : NULL;
1008 void MainInputManager::customEvent( QEvent *event )
1010 int type = event->type();
1014 // msg_Dbg( p_intf, "New MainIM Event of type: %i", type );
1017 case VolumeChanged_Type:
1018 emit volumeChanged();
1020 case SoundMuteChanged_Type:
1021 emit soundMuteChanged();
1023 case PLItemAppended_Type:
1024 plEv = static_cast<PLEvent*>( event );
1025 emit playlistItemAppended( plEv->i_item, plEv->i_parent );
1027 case PLItemRemoved_Type:
1028 plEv = static_cast<PLEvent*>( event );
1029 emit playlistItemRemoved( plEv->i_item );
1031 case RandomChanged_Type:
1032 emit randomChanged( var_GetBool( THEPL, "random" ) );
1034 case LoopChanged_Type:
1035 case RepeatChanged_Type:
1038 case LeafToParent_Type:
1039 plEv = static_cast<PLEvent*>( event );
1040 emit leafBecameParent( plEv->i_item );
1043 if( type != ItemChanged_Type ) return;
1046 /* Should be PLItemChanged Event */
1047 if( !p_intf->p_sys->b_isDialogProvider )
1049 if( p_input && ( p_input->b_dead || !vlc_object_alive (p_input) ) )
1051 emit inputChanged( p_input );
1052 var_DelCallback( p_input, "state", PLItemChanged, this );
1053 vlc_object_release( p_input );
1060 p_input = playlist_CurrentInput(THEPL);
1063 var_AddCallback( p_input, "state", PLItemChanged, this );
1064 emit inputChanged( p_input );
1070 /* remove previous stored p_input */
1073 vlc_object_release( p_input );
1076 /* we are working as a dialogs provider */
1077 p_input = playlist_CurrentInput( pl_Get(p_intf) );
1080 emit inputChanged( p_input );
1085 /* Playlist Control functions */
1086 void MainInputManager::stop()
1088 playlist_Stop( THEPL );
1091 void MainInputManager::next()
1093 playlist_Next( THEPL );
1096 void MainInputManager::prev()
1098 playlist_Prev( THEPL );
1101 void MainInputManager::prevOrReset()
1103 if( !p_input || var_GetTime( p_input , "time") < 10000 )
1104 playlist_Prev( THEPL );
1106 getIM()->sliderUpdate( 0.0 );
1109 void MainInputManager::togglePlayPause()
1111 /* No input, play */
1113 playlist_Play( THEPL );
1115 getIM()->togglePlayPause();
1118 void MainInputManager::play()
1120 /* No input, play */
1122 playlist_Play( THEPL );
1125 if( PLAYING_S != var_GetInteger( p_input, "state" ) )
1127 getIM()->togglePlayPause();
1132 void MainInputManager::pause()
1134 if(p_input && PLAYING_S == var_GetInteger( p_input, "state" ) )
1136 getIM()->togglePlayPause();
1140 void MainInputManager::toggleRandom()
1142 var_ToggleBool( THEPL, "random" );
1145 void MainInputManager::notifyRepeatLoop()
1147 int i_value = var_GetBool( THEPL, "loop" ) * REPEAT_ALL
1148 + var_GetBool( THEPL, "repeat" ) * REPEAT_ONE;
1150 emit repeatLoopChanged( i_value );
1153 void MainInputManager::loopRepeatLoopStatus()
1155 /* Toggle Normal -> Loop -> Repeat -> Normal ... */
1156 if( var_GetBool( THEPL, "repeat" ) )
1157 var_SetBool( THEPL, "repeat", false );
1158 else if( var_GetBool( THEPL, "loop" ) )
1160 var_SetBool( THEPL, "loop", false );
1161 var_SetBool( THEPL, "repeat", true );
1164 var_SetBool( THEPL, "loop", true );
1167 void MainInputManager::activatePlayQuit( bool b_exit )
1169 var_SetBool( THEPL, "play-and-exit", b_exit );
1172 bool MainInputManager::getPlayExitState()
1174 return var_GetBool( THEPL, "play-and-exit" );
1177 /****************************
1178 * Static callbacks for MIM *
1179 ****************************/
1180 static int PLItemChanged( vlc_object_t *p_this, const char *psz_var,
1181 vlc_value_t oldval, vlc_value_t, void *param )
1183 VLC_UNUSED( p_this ); VLC_UNUSED( psz_var ); VLC_UNUSED( oldval );
1185 MainInputManager *mim = (MainInputManager*)param;
1187 IMEvent *event = new IMEvent( ItemChanged_Type );
1188 QApplication::postEvent( mim, event );
1192 static int LeafToParent( vlc_object_t *p_this, const char *psz_var,
1193 vlc_value_t oldval, vlc_value_t newval, void *param )
1195 VLC_UNUSED( p_this ); VLC_UNUSED( psz_var ); VLC_UNUSED( oldval );
1196 MainInputManager *mim = (MainInputManager*)param;
1198 PLEvent *event = new PLEvent( LeafToParent_Type, newval.i_int );
1200 QApplication::postEvent( mim, event );
1204 static int VolumeChanged( vlc_object_t *p_this, const char *psz_var,
1205 vlc_value_t oldval, vlc_value_t newval, void *param )
1207 VLC_UNUSED( p_this ); VLC_UNUSED( psz_var ); VLC_UNUSED( oldval ); VLC_UNUSED( newval );
1209 MainInputManager *mim = (MainInputManager*)param;
1211 IMEvent *event = new IMEvent( VolumeChanged_Type );
1212 QApplication::postEvent( mim, event );
1216 static int SoundMuteChanged( vlc_object_t *p_this, const char *psz_var,
1217 vlc_value_t oldval, vlc_value_t newval, void *param )
1219 VLC_UNUSED( p_this ); VLC_UNUSED( psz_var ); VLC_UNUSED( oldval ); VLC_UNUSED( newval );
1221 MainInputManager *mim = (MainInputManager*)param;
1223 IMEvent *event = new IMEvent( SoundMuteChanged_Type );
1224 QApplication::postEvent( mim, event );
1228 static int PLItemAppended
1229 ( vlc_object_t * obj, const char *var, vlc_value_t old, vlc_value_t cur, void *data )
1231 VLC_UNUSED( obj ); VLC_UNUSED( var ); VLC_UNUSED( old );
1233 MainInputManager *mim = static_cast<MainInputManager*>(data);
1234 playlist_add_t *p_add = static_cast<playlist_add_t*>( cur.p_address );
1236 PLEvent *event = new PLEvent( PLItemAppended_Type, p_add->i_item, p_add->i_node );
1237 QApplication::postEvent( mim, event );
1240 static int PLItemRemoved
1241 ( vlc_object_t * obj, const char *var, vlc_value_t old, vlc_value_t cur, void *data )
1243 VLC_UNUSED( obj ); VLC_UNUSED( var ); VLC_UNUSED( old );
1245 MainInputManager *mim = static_cast<MainInputManager*>(data);
1247 PLEvent *event = new PLEvent( PLItemRemoved_Type, cur.i_int, 0 );
1248 QApplication::postEvent( mim, event );
1252 static int RandomChanged
1253 ( vlc_object_t * obj, const char *var, vlc_value_t old, vlc_value_t cur, void *data )
1255 VLC_UNUSED( obj ); VLC_UNUSED( var ); VLC_UNUSED( old ); VLC_UNUSED( cur );
1257 MainInputManager *mim = static_cast<MainInputManager*>(data);
1259 IMEvent *event = new IMEvent( RandomChanged_Type );
1260 QApplication::postEvent( mim, event );
1264 /* Probably could be merged with next callback */
1265 static int LoopChanged
1266 ( vlc_object_t * obj, const char *var, vlc_value_t old, vlc_value_t cur, void *data )
1268 VLC_UNUSED( obj ); VLC_UNUSED( var ); VLC_UNUSED( old ); VLC_UNUSED( cur );
1270 MainInputManager *mim = static_cast<MainInputManager*>(data);
1272 IMEvent *event = new IMEvent( LoopChanged_Type );
1273 QApplication::postEvent( mim, event );
1277 static int RepeatChanged
1278 ( vlc_object_t * obj, const char *var, vlc_value_t old, vlc_value_t cur, void *data )
1280 VLC_UNUSED( obj ); VLC_UNUSED( var ); VLC_UNUSED( old ); VLC_UNUSED( cur );
1282 MainInputManager *mim = static_cast<MainInputManager*>(data);
1284 IMEvent *event = new IMEvent( RepeatChanged_Type );
1285 QApplication::postEvent( mim, event );