1 /*****************************************************************************
2 * vlm_slider_manager.cpp : Manage an input slider for a VLM stream
3 *****************************************************************************
4 * Copyright (C) 2000-2005 the VideoLAN team
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., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
27 #include "dialogs/vlm/vlm_slider_manager.hpp"
28 #include "dialogs/vlm/vlm_stream.hpp"
29 #include "dialogs/vlm/vlm_streampanel.hpp"
31 /*****************************************************************************
33 *****************************************************************************/
34 VLMSliderManager::VLMSliderManager( intf_thread_t *_p_intf,
35 VLMBroadcastStreamPanel *_p_sp )
41 slider = p_sp->p_slider;
43 b_slider_free = VLC_TRUE;
44 time_string = wxU( "0:00:00 / 0:00:00");
47 VLMSliderManager::~VLMSliderManager()
51 /*****************************************************************************
53 *****************************************************************************/
54 void VLMSliderManager::Update()
56 /* Update the input */
63 slider->SetValue( 0 );
64 UpdateButtons( VLC_TRUE );
67 else if( p_input->b_dead )
70 UpdateButtons( VLC_FALSE );
72 vlc_object_release( p_input );
76 if( p_input && !p_input->b_die )
80 /* Really manage the slider */
81 var_Get( p_input, "position", &pos );
83 if( pos.f_float > 0.0 && ! IsShown() ) ShowSlider();
84 else if( pos.f_float <= 0.0 ) HideSlider();
86 if( IsPlaying() && IsShown() )
88 /* Update the slider if the user isn't dragging it. */
91 char psz_time[ MSTRTIME_MAX_SIZE ];
92 char psz_total[ MSTRTIME_MAX_SIZE ];
96 /* Update the value */
97 if( pos.f_float >= 0.0 )
99 i_slider_pos = (int)(SLIDER_MAX_POS * pos.f_float);
101 slider->SetValue( i_slider_pos );
103 var_Get( p_input, "time", &time );
104 i_seconds = time.i_time / 1000000;
105 secstotimestr ( psz_time, i_seconds );
107 var_Get( p_input, "length", &time );
108 i_seconds = time.i_time / 1000000;
109 secstotimestr ( psz_total, i_seconds );
111 UpdateTime( psz_time, psz_total );
118 /*****************************************************************************
120 *****************************************************************************/
121 void VLMSliderManager::UpdateInput()
123 if( p_sp->GetStream()->p_media->i_instance == 0 )
129 p_input = p_sp->GetStream()->p_media->instance[0]->p_input;
132 void VLMSliderManager::UpdateButtons( vlc_bool_t b_play )
136 p_sp->TogglePlayButton( PLAYING_S );
140 p_sp->TogglePlayButton( PAUSE_S );
144 vlc_bool_t VLMSliderManager::IsShown()
146 return slider->IsEnabled();
149 void VLMSliderManager::ShowSlider()
154 void VLMSliderManager::HideSlider()
156 slider->SetValue( 0 );
158 UpdateTime( "0:00:00", "0:00:00" );
161 vlc_bool_t VLMSliderManager::IsFree()
163 return b_slider_free;
166 vlc_bool_t VLMSliderManager::IsPlaying()
168 return VLC_TRUE; /* Is it really useful ? */
171 void VLMSliderManager::UpdateTime( char *psz_time, char *psz_total )
173 time_string = wxU(psz_time) + wxString(wxT(" / ") ) +wxU(psz_total) ;
177 void VLMSliderManager::ProcessUpdate( wxScrollEvent &event )
181 if( event.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
182 || event.GetEventType() == wxEVT_SCROLL_ENDSCROLL )
185 if( i_slider_pos != event.GetPosition() && p_input )
188 pos.f_float = (float)event.GetPosition() / (float)SLIDER_MAX_POS;
190 var_Set( p_input, "position", pos );
194 b_slider_free = VLC_TRUE;
198 b_slider_free = VLC_FALSE;
202 /* Update stream date */
203 char psz_time[ MSTRTIME_MAX_SIZE ], psz_total[ MSTRTIME_MAX_SIZE ];
206 i_seconds = var_GetTime( p_input, "length" ) / I64C(1000000 );
207 secstotimestr( psz_total, i_seconds );
209 i_seconds = var_GetTime( p_input, "time" ) / I64C(1000000 );
210 secstotimestr( psz_time, i_seconds );
212 time_string = wxU(psz_time) + wxString(wxT(" / ") ) +wxU(psz_total) ;