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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
28 #include "dialogs/vlm/vlm_slider_manager.hpp"
29 #include "dialogs/vlm/vlm_stream.hpp"
30 #include "dialogs/vlm/vlm_streampanel.hpp"
32 /*****************************************************************************
34 *****************************************************************************/
35 VLMSliderManager::VLMSliderManager( intf_thread_t *_p_intf,
36 VLMBroadcastStreamPanel *_p_sp )
42 slider = p_sp->p_slider;
44 b_slider_free = VLC_TRUE;
45 time_string = wxU( "0:00:00 / 0:00:00");
48 VLMSliderManager::~VLMSliderManager()
52 /*****************************************************************************
54 *****************************************************************************/
55 void VLMSliderManager::Update()
57 /* Update the input */
64 slider->SetValue( 0 );
65 UpdateButtons( VLC_TRUE );
68 else if( p_input->b_dead )
71 UpdateButtons( VLC_FALSE );
73 vlc_object_release( p_input );
77 if( p_input && !p_input->b_die )
81 /* Really manage the slider */
82 var_Get( p_input, "position", &pos );
84 if( pos.f_float > 0.0 && ! IsShown() ) ShowSlider();
85 else if( pos.f_float <= 0.0 ) HideSlider();
87 if( IsPlaying() && IsShown() )
89 /* Update the slider if the user isn't dragging it. */
92 char psz_time[ MSTRTIME_MAX_SIZE ];
93 char psz_total[ MSTRTIME_MAX_SIZE ];
97 /* Update the value */
98 if( pos.f_float >= 0.0 )
100 i_slider_pos = (int)(SLIDER_MAX_POS * pos.f_float);
102 slider->SetValue( i_slider_pos );
104 var_Get( p_input, "time", &time );
105 i_seconds = time.i_time / 1000000;
106 secstotimestr ( psz_time, i_seconds );
108 var_Get( p_input, "length", &time );
109 i_seconds = time.i_time / 1000000;
110 secstotimestr ( psz_total, i_seconds );
112 UpdateTime( psz_time, psz_total );
119 /*****************************************************************************
121 *****************************************************************************/
122 void VLMSliderManager::UpdateInput()
124 if( p_sp->GetStream()->p_media->i_instance == 0 )
130 p_input = p_sp->GetStream()->p_media->instance[0]->p_input;
133 void VLMSliderManager::UpdateButtons( vlc_bool_t b_play )
137 p_sp->TogglePlayButton( PLAYING_S );
141 p_sp->TogglePlayButton( PAUSE_S );
145 vlc_bool_t VLMSliderManager::IsShown()
147 return slider->IsEnabled();
150 void VLMSliderManager::ShowSlider()
155 void VLMSliderManager::HideSlider()
157 slider->SetValue( 0 );
159 UpdateTime( "0:00:00", "0:00:00" );
162 vlc_bool_t VLMSliderManager::IsFree()
164 return b_slider_free;
167 vlc_bool_t VLMSliderManager::IsPlaying()
169 return VLC_TRUE; /* Is it really useful ? */
172 void VLMSliderManager::UpdateTime( char *psz_time, char *psz_total )
174 time_string = wxU(psz_time) + wxString(wxT(" / ") ) +wxU(psz_total) ;
178 void VLMSliderManager::ProcessUpdate( wxScrollEvent &event )
182 if( event.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
183 || event.GetEventType() == wxEVT_SCROLL_ENDSCROLL )
186 if( i_slider_pos != event.GetPosition() && p_input )
189 pos.f_float = (float)event.GetPosition() / (float)SLIDER_MAX_POS;
191 var_Set( p_input, "position", pos );
195 b_slider_free = VLC_TRUE;
199 b_slider_free = VLC_FALSE;
203 /* Update stream date */
204 char psz_time[ MSTRTIME_MAX_SIZE ], psz_total[ MSTRTIME_MAX_SIZE ];
207 i_seconds = var_GetTime( p_input, "length" ) / I64C(1000000 );
208 secstotimestr( psz_total, i_seconds );
210 i_seconds = var_GetTime( p_input, "time" ) / I64C(1000000 );
211 secstotimestr( psz_time, i_seconds );
213 time_string = wxU(psz_time) + wxString(wxT(" / ") ) +wxU(psz_total) ;