1 /*****************************************************************************
2 * input_manager.cpp : Manage an input and interact with its GUI elements
3 ****************************************************************************
4 * Copyright (C) 2000-2005 the VideoLAN team
5 * $Id: wxwidgets.cpp 15731 2006-05-25 14:43:53Z zorglub $
7 * Authors: Clément Stenac <zorglub@videolan.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
26 #include "input_manager.hpp"
27 #include "dialogs_provider.hpp"
30 /**********************************************************************
31 * InputManager implementation
32 **********************************************************************/
34 InputManager::InputManager( QObject *parent, intf_thread_t *_p_intf) :
35 QObject( parent ), p_intf( _p_intf )
38 /* Subscribe to updates */
39 connect( DialogsProvider::getInstance( p_intf )->fixed_timer,
40 SIGNAL( timeout() ), this, SLOT( update() ) );
43 InputManager::~InputManager()
47 void InputManager::setInput( input_thread_t *_p_input )
50 emit positionUpdated( 0.0,0,0 );
53 void InputManager::update()
55 /// \todo Emit the signals only if it changed
56 if( !p_input || p_input->b_die ) return;
60 emit positionUpdated( 0.0, 0, 0 );
61 emit navigationChanged( 0 );
62 emit statusChanged( 0 ); // 0 = STOPPED, 1 = PAUSE, 2 = PLAY
66 mtime_t i_length, i_time;
68 i_length = var_GetTime( p_input, "length" ) / 1000000;
69 i_time = var_GetTime( p_input, "time") / 1000000;
70 f_pos = var_GetFloat( p_input, "position" );
71 emit positionUpdated( f_pos, i_time, i_length );
73 /* Update disc status */
75 var_Change( p_input, "title", VLC_VAR_CHOICESCOUNT, &val, NULL );
79 var_Change( p_input, "chapter", VLC_VAR_CHOICESCOUNT, &val, NULL );
81 emit navigationChanged( 1 ); // 1 = chapter, 2 = title, 3 = NO
83 emit navigationChanged( 2 );
87 emit navigationChanged( 0 );
92 if( p_input->input.p_item->p_meta &&
93 p_input->input.p_item->p_meta->psz_nowplaying &&
94 *p_input->input.p_item->p_meta->psz_nowplaying )
96 text.sprintf( "%s - %s",
97 p_input->input.p_item->p_meta->psz_nowplaying,
98 p_input->input.p_item->psz_name );
102 text.sprintf( "%s", p_input->input.p_item->psz_name );
104 emit nameChanged( text );
108 void InputManager::sliderUpdate( float new_pos )
110 if( p_input && !p_input->b_die && !p_input->b_dead )
111 var_SetFloat( p_input, "position", new_pos );
114 /**********************************************************************
115 * MainInputManager implementation. Wrap an input manager and
116 * take care of updating the main playlist input
117 **********************************************************************/
118 MainInputManager * MainInputManager::instance = NULL;
120 MainInputManager::MainInputManager( intf_thread_t *_p_intf ) : QObject(NULL),
124 im = new InputManager( this, p_intf );
125 /* Get timer updates */
126 connect( DialogsProvider::getInstance(p_intf)->fixed_timer,
127 SIGNAL(timeout() ), this, SLOT( updateInput() ) );
128 /* Warn our embedded IM about input changes */
129 connect( this, SIGNAL( inputChanged( input_thread_t * ) ),
130 im, SLOT( setInput( input_thread_t * ) ) );
133 void MainInputManager::updateInput()
135 vlc_mutex_lock( &p_intf->change_lock );
136 if( p_input && p_input->b_dead )
138 vlc_object_release( p_input );
140 emit inputChanged( NULL );
145 playlist_t *p_playlist = (playlist_t *) vlc_object_find( p_intf,
146 VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
147 assert( p_playlist );
149 p_input = p_playlist->p_input;
152 vlc_object_yield( p_input );
153 emit inputChanged( p_input );
156 vlc_object_release( p_playlist );
158 vlc_mutex_unlock( &p_intf->change_lock );