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"
34 #include "recents.hpp"
36 #include <vlc_keys.h> /* ACTION_ID */
37 #include <vlc_url.h> /* decode_URI */
38 #include <vlc_strings.h> /* str_format_meta */
39 #include <vlc_aout.h> /* audio_output_t */
41 #include <QApplication>
44 #include <QSignalMapper>
45 #include <QMessageBox>
49 static int ItemChanged( vlc_object_t *, const char *,
50 vlc_value_t, vlc_value_t, void * );
51 static int LeafToParent( vlc_object_t *, const char *,
52 vlc_value_t, vlc_value_t, void * );
53 static int PLItemChanged( vlc_object_t *, const char *,
54 vlc_value_t, vlc_value_t, void * );
55 static int PLItemAppended( vlc_object_t *, const char *,
56 vlc_value_t, vlc_value_t, void * );
57 static int PLItemRemoved( vlc_object_t *, const char *,
58 vlc_value_t, vlc_value_t, void * );
60 static int InputEvent( vlc_object_t *, const char *,
61 vlc_value_t, vlc_value_t, void * );
62 static int VbiEvent( vlc_object_t *, const char *,
63 vlc_value_t, vlc_value_t, void * );
65 /* Ensure arbitratry (not dynamically allocated) event IDs are not in use */
66 static inline void registerAndCheckEventIds( int start, int end )
68 for ( int i=start ; i<=end ; i++ )
69 Q_ASSERT( QEvent::registerEventType( i ) == i ); /* event ID collision ! */
72 /**********************************************************************
73 * InputManager implementation
74 **********************************************************************
75 * The Input Manager can be the main one around the playlist
76 * But can also be used for VLM dialog or similar
77 **********************************************************************/
79 InputManager::InputManager( QObject *parent, intf_thread_t *_p_intf) :
80 QObject( parent ), p_intf( _p_intf )
82 i_old_playing_status = END_S;
92 f_cache = -1.; /* impossible initial value, different from all */
93 registerAndCheckEventIds( IMEvent::PositionUpdate, IMEvent::FullscreenControlPlanHide );
94 registerAndCheckEventIds( PLEvent::PLItemAppended, PLEvent::PLEmpty );
97 InputManager::~InputManager()
102 void InputManager::inputChangedHandler()
104 setInput( THEMIM->getInput() );
107 /* Define the Input used.
108 Add the callbacks on input
109 p_input is held once here */
110 void InputManager::setInput( input_thread_t *_p_input )
114 if( p_input != NULL )
116 msg_Dbg( p_intf, "IM: Setting an input" );
117 vlc_object_hold( p_input );
127 p_item = input_GetItem( p_input );
128 emit rateChanged( var_GetFloat( p_input, "rate" ) );
131 if( p_item->i_type == ITEM_TYPE_FILE )
133 int i_time = RecentsMRL::getInstance( p_intf )->time( p_item->psz_uri );
135 !var_GetFloat( p_input, "run-time" ) &&
136 !var_GetFloat( p_input, "start-time" ) &&
137 !var_GetFloat( p_input, "stop-time" ) )
139 emit resumePlayback( (int64_t)i_time * 1000 );
146 assert( !p_input_vbi );
147 emit rateChanged( var_InheritFloat( p_intf, "rate" ) );
151 /* delete Input if it ever existed.
152 Delete the callbacls on input
153 p_input is released once here */
154 void InputManager::delInput()
156 if( !p_input ) return;
157 msg_Dbg( p_intf, "IM: Deleting the input" );
159 /* Save time / position */
160 float f_pos = var_GetFloat( p_input , "position" );
161 int64_t i_time = var_GetTime( p_input, "time");
162 int i_length = var_GetTime( p_input , "length" ) / CLOCK_FREQ;
163 if( f_pos < 0.05 || f_pos > 0.95 || i_length < 60) {
166 RecentsMRL::getInstance( p_intf )->setTime( p_item->psz_uri, i_time );
169 i_old_playing_status = END_S;
180 vlc_object_release( p_input_vbi );
184 vlc_object_release( p_input );
187 emit positionUpdated( -1.0, 0 ,0 );
188 emit rateChanged( var_InheritFloat( p_intf, "rate" ) );
189 emit nameChanged( "" );
190 emit chapterChanged( 0 );
191 emit titleChanged( 0 );
192 emit playingStatusChanged( END_S );
194 emit teletextPossible( false );
195 emit AtoBchanged( false, false );
196 emit voutChanged( false );
197 emit voutListChanged( NULL, 0 );
199 /* Reset all InfoPanels but stats */
200 emit artChanged( NULL );
201 emit artChanged( "" );
202 emit infoChanged( NULL );
203 emit currentMetaChanged( (input_item_t *)NULL );
205 emit encryptionChanged( false );
206 emit recordingStateChanged( false );
208 emit cachingChanged( 1 );
211 /* Convert the event from the callbacks in actions */
212 void InputManager::customEvent( QEvent *event )
214 int i_type = event->type();
215 IMEvent *ple = static_cast<IMEvent *>(event);
217 if( i_type == IMEvent::ItemChanged )
218 UpdateMeta( ple->item() );
226 case IMEvent::PositionUpdate:
229 case IMEvent::StatisticsUpdate:
232 case IMEvent::ItemChanged:
233 /* Ignore ItemChanged_Type event that does not apply to our input */
234 if( p_item == ple->item() )
240 /* Update duration of file */
243 case IMEvent::ItemStateChanged:
246 case IMEvent::NameChanged:
249 case IMEvent::MetaChanged:
251 UpdateName(); /* Needed for NowPlaying */
252 UpdateArt(); /* Art is part of meta in the core */
254 case IMEvent::InfoChanged:
257 case IMEvent::ItemTitleChanged:
259 UpdateName(); /* Display the name of the Chapter, if exists */
261 case IMEvent::ItemRateChanged:
264 case IMEvent::ItemEsChanged:
266 // We don't do anything ES related. Why ?
268 case IMEvent::ItemTeletextChanged:
271 case IMEvent::InterfaceVoutUpdate:
274 case IMEvent::SynchroChanged:
275 emit synchroChanged();
277 case IMEvent::CachingEvent:
280 case IMEvent::BookmarksChanged:
281 emit bookmarksChanged();
283 case IMEvent::InterfaceAoutUpdate:
286 case IMEvent::RecordingEvent:
289 case IMEvent::ProgramChanged:
290 UpdateProgramEvent();
292 case IMEvent::EPGEvent:
296 msg_Warn( p_intf, "This shouldn't happen: %i", i_type );
301 /* Add the callbacks on Input. Self explanatory */
302 inline void InputManager::addCallbacks()
304 var_AddCallback( p_input, "intf-event", InputEvent, this );
307 /* Delete the callbacks on Input. Self explanatory */
308 inline void InputManager::delCallbacks()
310 var_DelCallback( p_input, "intf-event", InputEvent, this );
313 /* Static callbacks for IM */
314 static int ItemChanged( vlc_object_t *p_this, const char *psz_var,
315 vlc_value_t oldval, vlc_value_t newval, void *param )
317 VLC_UNUSED( p_this ); VLC_UNUSED( psz_var ); VLC_UNUSED( oldval );
319 InputManager *im = (InputManager*)param;
320 input_item_t *p_item = static_cast<input_item_t *>(newval.p_address);
322 IMEvent *event = new IMEvent( IMEvent::ItemChanged, p_item );
323 QApplication::postEvent( im, event );
327 static int InputEvent( vlc_object_t *p_this, const char *,
328 vlc_value_t, vlc_value_t newval, void *param )
330 VLC_UNUSED( p_this );
332 InputManager *im = (InputManager*)param;
335 switch( newval.i_int )
337 case INPUT_EVENT_STATE:
338 event = new IMEvent( IMEvent::ItemStateChanged );
340 case INPUT_EVENT_RATE:
341 event = new IMEvent( IMEvent::ItemRateChanged );
343 case INPUT_EVENT_POSITION:
344 //case INPUT_EVENT_LENGTH:
345 event = new IMEvent( IMEvent::PositionUpdate );
348 case INPUT_EVENT_TITLE:
349 case INPUT_EVENT_CHAPTER:
350 event = new IMEvent( IMEvent::ItemTitleChanged );
354 event = new IMEvent( IMEvent::ItemEsChanged );
356 case INPUT_EVENT_TELETEXT:
357 event = new IMEvent( IMEvent::ItemTeletextChanged );
360 case INPUT_EVENT_STATISTICS:
361 event = new IMEvent( IMEvent::StatisticsUpdate );
364 case INPUT_EVENT_VOUT:
365 event = new IMEvent( IMEvent::InterfaceVoutUpdate );
367 case INPUT_EVENT_AOUT:
368 event = new IMEvent( IMEvent::InterfaceAoutUpdate );
371 case INPUT_EVENT_ITEM_META: /* Codec MetaData + Art */
372 event = new IMEvent( IMEvent::MetaChanged );
374 case INPUT_EVENT_ITEM_INFO: /* Codec Info */
375 event = new IMEvent( IMEvent::InfoChanged );
377 case INPUT_EVENT_ITEM_NAME:
378 event = new IMEvent( IMEvent::NameChanged );
381 case INPUT_EVENT_AUDIO_DELAY:
382 case INPUT_EVENT_SUBTITLE_DELAY:
383 event = new IMEvent( IMEvent::SynchroChanged );
386 case INPUT_EVENT_CACHE:
387 event = new IMEvent( IMEvent::CachingEvent );
390 case INPUT_EVENT_BOOKMARK:
391 event = new IMEvent( IMEvent::BookmarksChanged );
394 case INPUT_EVENT_RECORD:
395 event = new IMEvent( IMEvent::RecordingEvent );
398 case INPUT_EVENT_PROGRAM:
399 /* This is for PID changes */
400 event = new IMEvent( IMEvent::ProgramChanged );
403 case INPUT_EVENT_ITEM_EPG:
404 /* EPG data changed */
405 event = new IMEvent( IMEvent::EPGEvent );
408 case INPUT_EVENT_SIGNAL:
409 /* This is for capture-card signals */
410 /* event = new IMEvent( SignalChanged_Type );
418 QApplication::postEvent( im, event );
422 static int VbiEvent( vlc_object_t *, const char *,
423 vlc_value_t, vlc_value_t, void *param )
425 InputManager *im = (InputManager*)param;
426 IMEvent *event = new IMEvent( IMEvent::ItemTeletextChanged );
428 QApplication::postEvent( im, event );
432 void InputManager::UpdatePosition()
434 /* Update position */
438 i_length = var_GetTime( p_input , "length" ) / CLOCK_FREQ;
439 i_time = var_GetTime( p_input , "time");
440 f_pos = var_GetFloat( p_input , "position" );
441 emit positionUpdated( f_pos, i_time, i_length );
444 void InputManager::UpdateNavigation()
446 /* Update navigation status */
447 vlc_value_t val; val.i_int = 0;
448 vlc_value_t val2; val2.i_int = 0;
451 var_Change( p_input, "title", VLC_VAR_CHOICESCOUNT, &val, NULL );
455 /* p_input != NULL since val.i_int != 0 */
456 var_Change( p_input, "chapter", VLC_VAR_CHOICESCOUNT, &val2, NULL );
458 emit titleChanged( val.i_int > 1 );
459 emit chapterChanged( val2.i_int > 1 );
462 emit chapterChanged( false );
465 emit inputCanSeek( var_GetBool( p_input, "can-seek" ) );
467 emit inputCanSeek( false );
470 void InputManager::UpdateStatus()
472 /* Update playing status */
473 int state = var_GetInteger( p_input, "state" );
474 if( i_old_playing_status != state )
476 i_old_playing_status = state;
477 emit playingStatusChanged( state );
481 void InputManager::UpdateRate()
484 float f_new_rate = var_GetFloat( p_input, "rate" );
485 if( f_new_rate != f_rate )
489 emit rateChanged( f_rate );
493 void InputManager::UpdateName()
497 /* Update text, name and nowplaying */
500 /* Try to get the nowplaying */
501 char *format = var_InheritString( p_intf, "input-title-format" );
502 char *formated = str_format_meta( p_input, format );
504 name = qfu(formated);
507 /* If we have Nothing */
508 if( name.simplified().isEmpty() )
510 char *uri = input_item_GetURI( input_GetItem( p_input ) );
511 char *file = uri ? strrchr( uri, '/' ) : NULL;
514 decode_URI( ++file );
522 name = name.trimmed();
524 if( oldName != name )
526 emit nameChanged( name );
531 int InputManager::playingStatus()
533 return i_old_playing_status;
536 bool InputManager::hasAudio()
541 var_Change( p_input, "audio-es", VLC_VAR_CHOICESCOUNT, &val, NULL );
542 return val.i_int > 0;
547 bool InputManager::hasVisualisation()
552 audio_output_t *aout = input_GetAout( p_input );
556 char *visual = var_InheritString( aout, "visual" );
557 vlc_object_release( aout );
566 void InputManager::UpdateTeletext()
570 const bool b_enabled = var_CountChoices( p_input, "teletext-es" ) > 0;
571 const int i_teletext_es = var_GetInteger( p_input, "teletext-es" );
573 /* Teletext is possible. Show the buttons */
574 emit teletextPossible( b_enabled );
576 /* If Teletext is selected */
577 if( b_enabled && i_teletext_es >= 0 )
579 /* Then, find the current page */
581 bool b_transparent = false;
585 var_DelCallback( p_input_vbi, "vbi-page", VbiEvent, this );
586 vlc_object_release( p_input_vbi );
589 if( input_GetEsObjects( p_input, i_teletext_es, &p_input_vbi, NULL, NULL ) )
594 /* This callback is not remove explicitly, but interfaces
595 * are guaranted to outlive input */
596 var_AddCallback( p_input_vbi, "vbi-page", VbiEvent, this );
598 i_page = var_GetInteger( p_input_vbi, "vbi-page" );
599 b_transparent = !var_GetBool( p_input_vbi, "vbi-opaque" );
601 emit newTelexPageSet( i_page );
602 emit teletextTransparencyActivated( b_transparent );
605 emit teletextActivated( b_enabled && i_teletext_es >= 0 );
609 emit teletextActivated( false );
610 emit teletextPossible( false );
614 void InputManager::UpdateEPG()
622 void InputManager::UpdateVout()
626 /* Get current vout lists from input */
628 vout_thread_t **pp_vout;
629 if( input_Control( p_input, INPUT_GET_VOUTS, &pp_vout, &i_vout ) )
636 emit voutListChanged( pp_vout, i_vout );
639 bool b_old_video = b_video;
640 b_video = i_vout > 0;
641 if( !!b_old_video != !!b_video )
642 emit voutChanged( b_video );
644 /* Release the vout list */
645 for( size_t i = 0; i < i_vout; i++ )
646 vlc_object_release( (vlc_object_t*)pp_vout[i] );
650 void InputManager::UpdateAout()
657 void InputManager::UpdateCaching()
659 if(!hasInput()) return;
661 float f_newCache = var_GetFloat ( p_input, "cache" );
662 if( f_newCache != f_cache )
664 f_cache = f_newCache;
666 emit cachingChanged( f_cache );
670 void InputManager::requestArtUpdate( input_item_t *p_item, bool b_forced )
672 bool b_current_item = false;
673 if ( !p_item && hasInput() )
674 { /* default to current item */
675 p_item = input_GetItem( p_input );
676 b_current_item = true;
681 /* check if it has already been enqueued */
682 if ( p_item->p_meta && !b_forced )
684 int status = vlc_meta_GetStatus( p_item->p_meta );
685 if ( status & ( ITEM_ART_NOTFOUND|ITEM_ART_FETCHED ) )
688 libvlc_ArtRequest( p_intf->p_libvlc, p_item,
689 (b_forced) ? META_REQUEST_OPTION_SCOPE_ANY
690 : META_REQUEST_OPTION_NONE );
691 /* No input will signal the cover art to update,
692 * let's do it ourself */
693 if ( b_current_item )
696 emit artChanged( p_item );
700 const QString InputManager::decodeArtURL( input_item_t *p_item )
704 char *psz_art = input_item_GetArtURL( p_item );
707 char *psz = make_path( psz_art );
713 /* Taglib seems to define a attachment://, It won't work yet */
714 url = url.replace( "attachment://", "" );
717 QString path = qfu( psz_art ? psz_art : "" );
722 void InputManager::UpdateArt()
727 url = decodeArtURL( input_GetItem( p_input ) );
729 /* the art hasn't changed, no need to update */
733 /* Update Art meta */
735 emit artChanged( artUrl );
738 void InputManager::setArt( input_item_t *p_item, QString fileUrl )
742 char *psz_cachedir = config_GetUserDir( VLC_CACHE_DIR );
743 QString old_url = THEMIM->getIM()->decodeArtURL( p_item );
744 old_url = QDir( old_url ).canonicalPath();
746 if( old_url.startsWith( QString::fromUtf8( psz_cachedir ) ) )
747 QFile( old_url ).remove(); /* Purge cached artwork */
749 free( psz_cachedir );
751 input_item_SetArtURL( p_item , fileUrl.toUtf8().constData() );
756 inline void InputManager::UpdateStats()
759 emit statisticsUpdated( input_GetItem( p_input ) );
762 inline void InputManager::UpdateMeta( input_item_t *p_item_ )
764 emit metaChanged( p_item_ );
765 emit artChanged( p_item_ );
768 inline void InputManager::UpdateMeta()
771 emit currentMetaChanged( input_GetItem( p_input ) );
774 inline void InputManager::UpdateInfo()
777 emit infoChanged( input_GetItem( p_input ) );
780 void InputManager::UpdateRecord()
784 emit recordingStateChanged( var_GetBool( p_input, "record" ) );
788 void InputManager::UpdateProgramEvent()
792 bool b_scrambled = var_GetBool( p_input, "program-scrambled" );
793 emit encryptionChanged( b_scrambled );
797 /* User update of the slider */
798 void InputManager::sliderUpdate( float new_pos )
801 var_SetFloat( p_input, "position", new_pos );
802 emit seekRequested( new_pos );
805 void InputManager::sectionPrev()
809 int i_type = var_Type( p_input, "next-chapter" );
810 var_TriggerCallback( p_input, (i_type & VLC_VAR_TYPE) != 0 ?
811 "prev-chapter":"prev-title" );
815 void InputManager::sectionNext()
819 int i_type = var_Type( p_input, "next-chapter" );
820 var_TriggerCallback( p_input, (i_type & VLC_VAR_TYPE) != 0 ?
821 "next-chapter":"next-title" );
825 void InputManager::sectionMenu()
829 vlc_value_t val, text;
831 if( var_Change( p_input, "title 0", VLC_VAR_GETCHOICES, &val, &text ) < 0 )
834 /* XXX is it "Root" or "Title" we want here ?" (set 0 by default) */
836 for( int i = 0; i < val.p_list->i_count; i++ )
838 if( !strcmp( text.p_list->p_values[i].psz_string, "Title" ) )
841 var_FreeList( &val, &text );
843 var_SetInteger( p_input, "title 0", root );
851 /* Set a new Teletext Page */
852 void InputManager::telexSetPage( int page )
854 if( hasInput() && p_input_vbi )
856 const int i_teletext_es = var_GetInteger( p_input, "teletext-es" );
858 if( i_teletext_es >= 0 )
860 var_SetInteger( p_input_vbi, "vbi-page", page );
861 emit newTelexPageSet( page );
866 /* Set the transparency on teletext */
867 void InputManager::telexSetTransparency( bool b_transparentTelextext )
869 if( hasInput() && p_input_vbi )
871 var_SetBool( p_input_vbi, "vbi-opaque", !b_transparentTelextext );
872 emit teletextTransparencyActivated( b_transparentTelextext );
876 void InputManager::activateTeletext( bool b_enable )
880 if( hasInput() && !var_Change( p_input, "teletext-es", VLC_VAR_GETCHOICES, &list, &text ) )
882 if( list.p_list->i_count > 0 )
884 /* Prefer the page 100 if it is present */
886 for( i = 0; i < text.p_list->i_count; i++ )
888 /* The description is the page number as a string */
889 const char *psz_page = text.p_list->p_values[i].psz_string;
890 if( psz_page && !strcmp( psz_page, "100" ) )
893 if( i >= list.p_list->i_count )
895 var_SetInteger( p_input, "spu-es", b_enable ? list.p_list->p_values[i].i_int : -1 );
897 var_FreeList( &list, &text );
901 void InputManager::reverse()
905 float f_rate_ = var_GetFloat( p_input, "rate" );
906 var_SetFloat( p_input, "rate", -f_rate_ );
910 void InputManager::slower()
912 var_TriggerCallback( THEPL, "rate-slower" );
915 void InputManager::faster()
917 var_TriggerCallback( THEPL, "rate-faster" );
920 void InputManager::littlefaster()
922 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_RATE_FASTER_FINE );
925 void InputManager::littleslower()
927 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_RATE_SLOWER_FINE );
930 void InputManager::normalRate()
932 var_SetFloat( THEPL, "rate", 1. );
935 void InputManager::setRate( int new_rate )
937 var_SetFloat( THEPL, "rate",
938 (float)INPUT_RATE_DEFAULT / (float)new_rate );
941 void InputManager::jumpFwd()
943 int i_interval = var_InheritInteger( p_input, "short-jump-size" );
944 if( i_interval > 0 && hasInput() )
946 mtime_t val = CLOCK_FREQ * i_interval;
947 var_SetTime( p_input, "time-offset", val );
951 void InputManager::jumpBwd()
953 int i_interval = var_InheritInteger( p_input, "short-jump-size" );
954 if( i_interval > 0 && hasInput() )
956 mtime_t val = -CLOCK_FREQ * i_interval;
957 var_SetTime( p_input, "time-offset", val );
961 void InputManager::setAtoB()
965 timeA = var_GetTime( THEMIM->getInput(), "time" );
969 timeB = var_GetTime( THEMIM->getInput(), "time" );
970 var_SetTime( THEMIM->getInput(), "time" , timeA );
971 CONNECT( this, positionUpdated( float, int64_t, int ),
972 this, AtoBLoop( float, int64_t, int ) );
978 disconnect( this, SIGNAL( positionUpdated( float, int64_t, int ) ),
979 this, SLOT( AtoBLoop( float, int64_t, int ) ) );
981 emit AtoBchanged( (timeA != 0 ), (timeB != 0 ) );
984 /* Function called regularly when in an AtoB loop */
985 void InputManager::AtoBLoop( float, int64_t i_time, int )
987 if( timeB && i_time >= timeB )
988 var_SetTime( THEMIM->getInput(), "time" , timeA );
991 /**********************************************************************
992 * MainInputManager implementation. Wrap an input manager and
993 * take care of updating the main playlist input.
994 * Used in the main playlist Dialog
995 **********************************************************************/
997 MainInputManager::MainInputManager( intf_thread_t *_p_intf )
998 : QObject(NULL), p_intf( _p_intf ),
999 random( VLC_OBJECT(THEPL), "random" ),
1000 repeat( VLC_OBJECT(THEPL), "repeat" ), loop( VLC_OBJECT(THEPL), "loop" ),
1001 volume( VLC_OBJECT(THEPL), "volume" ), mute( VLC_OBJECT(THEPL), "mute" )
1004 im = new InputManager( this, p_intf );
1006 var_AddCallback( THEPL, "item-change", ItemChanged, im );
1007 var_AddCallback( THEPL, "activity", PLItemChanged, this );
1008 var_AddCallback( THEPL, "leaf-to-parent", LeafToParent, this );
1009 var_AddCallback( THEPL, "playlist-item-append", PLItemAppended, this );
1010 var_AddCallback( THEPL, "playlist-item-deleted", PLItemRemoved, this );
1011 random.addCallback( this, SLOT(notifyRandom(bool)) );
1012 repeat.addCallback( this, SLOT(notifyRepeatLoop(bool)) );
1013 loop.addCallback( this, SLOT(notifyRepeatLoop(bool)) );
1015 volume.addCallback( this, SLOT(notifyVolume(float)) );
1016 mute.addCallback( this, SLOT(notifyMute(bool)) );
1018 /* Warn our embedded IM about input changes */
1019 DCONNECT( this, inputChanged(),
1020 im, inputChangedHandler() );
1022 /* initialize p_input (an input can already be running) */
1023 p_input = playlist_CurrentInput( THEPL );
1025 emit inputChanged( );
1028 menusAudioMapper = new QSignalMapper();
1029 CONNECT( menusAudioMapper, mapped(QString), this, menusUpdateAudio( QString ) );
1032 MainInputManager::~MainInputManager()
1036 vlc_object_release( p_input );
1038 emit inputChanged( );
1041 var_DelCallback( THEPL, "activity", PLItemChanged, this );
1042 var_DelCallback( THEPL, "item-change", ItemChanged, im );
1043 var_DelCallback( THEPL, "leaf-to-parent", LeafToParent, this );
1045 var_DelCallback( THEPL, "playlist-item-append", PLItemAppended, this );
1046 var_DelCallback( THEPL, "playlist-item-deleted", PLItemRemoved, this );
1048 delete menusAudioMapper;
1051 vout_thread_t* MainInputManager::getVout()
1053 return p_input ? input_GetVout( p_input ) : NULL;
1056 audio_output_t * MainInputManager::getAout()
1058 return playlist_GetAout( THEPL );
1061 void MainInputManager::customEvent( QEvent *event )
1063 int type = event->type();
1067 // msg_Dbg( p_intf, "New MainIM Event of type: %i", type );
1070 case PLEvent::PLItemAppended:
1071 plEv = static_cast<PLEvent*>( event );
1072 emit playlistItemAppended( plEv->getItemId(), plEv->getParentId() );
1074 case PLEvent::PLItemRemoved:
1075 plEv = static_cast<PLEvent*>( event );
1076 emit playlistItemRemoved( plEv->getItemId() );
1078 case PLEvent::PLEmpty:
1079 plEv = static_cast<PLEvent*>( event );
1080 emit playlistNotEmpty( plEv->getItemId() >= 0 );
1082 case PLEvent::LeafToParent:
1083 plEv = static_cast<PLEvent*>( event );
1084 emit leafBecameParent( plEv->getItemId() );
1087 if( type != IMEvent::ItemChanged ) return;
1090 if( p_input != NULL )
1091 vlc_object_release( p_input );
1092 p_input = playlist_CurrentInput( THEPL );
1093 emit inputChanged( );
1096 /* Playlist Control functions */
1097 void MainInputManager::stop()
1099 playlist_Stop( THEPL );
1102 void MainInputManager::next()
1104 playlist_Next( THEPL );
1107 void MainInputManager::prev()
1109 playlist_Prev( THEPL );
1112 void MainInputManager::prevOrReset()
1114 if( !p_input || var_GetTime( p_input , "time") < 10000 )
1115 playlist_Prev( THEPL );
1117 getIM()->sliderUpdate( 0.0 );
1120 void MainInputManager::togglePlayPause()
1122 /* No input, play */
1124 playlist_Play( THEPL );
1126 playlist_Pause( THEPL );
1129 void MainInputManager::play()
1131 /* No input, play */
1133 playlist_Play( THEPL );
1136 if( PLAYING_S != var_GetInteger( p_input, "state" ) )
1138 playlist_Pause( THEPL );
1143 void MainInputManager::pause()
1145 if(p_input && PLAYING_S == var_GetInteger( p_input, "state" ) )
1147 playlist_Pause( THEPL );
1151 void MainInputManager::toggleRandom()
1153 config_PutInt( p_intf, "random", var_ToggleBool( THEPL, "random" ) );
1156 void MainInputManager::notifyRandom(bool value)
1158 emit randomChanged(value);
1161 void MainInputManager::notifyRepeatLoop(bool)
1163 int i_value = var_GetBool( THEPL, "loop" ) * REPEAT_ALL
1164 + var_GetBool( THEPL, "repeat" ) * REPEAT_ONE;
1166 emit repeatLoopChanged( i_value );
1169 void MainInputManager::loopRepeatLoopStatus()
1171 /* Toggle Normal -> Loop -> Repeat -> Normal ... */
1172 bool loop = var_GetBool( THEPL, "loop" );
1173 bool repeat = var_GetBool( THEPL, "repeat" );
1191 var_SetBool( THEPL, "loop", loop );
1192 var_SetBool( THEPL, "repeat", repeat );
1193 config_PutInt( p_intf, "loop", loop );
1194 config_PutInt( p_intf, "repeat", repeat );
1197 void MainInputManager::activatePlayQuit( bool b_exit )
1199 var_SetBool( THEPL, "play-and-exit", b_exit );
1200 config_PutInt( p_intf, "play-and-exit", b_exit );
1203 bool MainInputManager::getPlayExitState()
1205 return var_InheritBool( THEPL, "play-and-exit" );
1208 bool MainInputManager::hasEmptyPlaylist()
1210 playlist_Lock( THEPL );
1211 bool b_empty = playlist_IsEmpty( THEPL );
1212 playlist_Unlock( THEPL );
1216 /****************************
1217 * Static callbacks for MIM *
1218 ****************************/
1219 static int PLItemChanged( vlc_object_t *p_this, const char *psz_var,
1220 vlc_value_t oldval, vlc_value_t val, void *param )
1222 VLC_UNUSED( p_this ); VLC_UNUSED( psz_var ); VLC_UNUSED( oldval );
1225 MainInputManager *mim = (MainInputManager*)param;
1227 IMEvent *event = new IMEvent( IMEvent::ItemChanged );
1228 QApplication::postEvent( mim, event );
1232 static int LeafToParent( vlc_object_t *p_this, const char *psz_var,
1233 vlc_value_t oldval, vlc_value_t newval, void *param )
1235 VLC_UNUSED( p_this ); VLC_UNUSED( psz_var ); VLC_UNUSED( oldval );
1236 MainInputManager *mim = (MainInputManager*)param;
1238 PLEvent *event = new PLEvent( PLEvent::LeafToParent, newval.i_int );
1240 QApplication::postEvent( mim, event );
1244 void MainInputManager::notifyVolume( float volume )
1246 emit volumeChanged( volume );
1249 void MainInputManager::notifyMute( bool mute )
1251 emit soundMuteChanged(mute);
1255 void MainInputManager::menusUpdateAudio( const QString& data )
1257 audio_output_t *aout = getAout();
1260 aout_DeviceSet( aout, qtu(data) );
1261 vlc_object_release( aout );
1265 static int PLItemAppended
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 );
1269 MainInputManager *mim = static_cast<MainInputManager*>(data);
1270 playlist_add_t *p_add = static_cast<playlist_add_t*>( cur.p_address );
1272 PLEvent *event = new PLEvent( PLEvent::PLItemAppended, p_add->i_item, p_add->i_node );
1273 QApplication::postEvent( mim, event );
1274 event = new PLEvent( PLEvent::PLEmpty, p_add->i_item, 0 );
1275 QApplication::postEvent( mim, event );
1279 static int PLItemRemoved
1280 ( vlc_object_t * obj, const char *var, vlc_value_t old, vlc_value_t cur, void *data )
1282 VLC_UNUSED( var ); VLC_UNUSED( old );
1284 playlist_t *pl = (playlist_t *) obj;
1285 MainInputManager *mim = static_cast<MainInputManager*>(data);
1287 PLEvent *event = new PLEvent( PLEvent::PLItemRemoved, cur.i_int, 0 );
1288 QApplication::postEvent( mim, event );
1289 // can't use playlist_IsEmpty( ) as it isn't true yet
1290 if ( pl->items.i_size == 1 ) // lock is held
1292 event = new PLEvent( PLEvent::PLEmpty, -1, 0 );
1293 QApplication::postEvent( mim, event );