]> git.sesse.net Git - vlc/blob - modules/gui/wxwidgets/dialogs/vlm/vlm_slider_manager.cpp
update module LIST file.
[vlc] / modules / gui / wxwidgets / dialogs / vlm / vlm_slider_manager.cpp
1 /*****************************************************************************
2  * vlm_slider_manager.cpp : Manage an input slider for a VLM stream
3  *****************************************************************************
4  * Copyright (C) 2000-2005 the VideoLAN team
5  * $Id$
6  *
7  * Authors: ClĂ©ment Stenac <zorglub@videolan.org>
8  *
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.
13  *
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.
18  *
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  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #if 0
28 #include "dialogs/vlm/vlm_slider_manager.hpp"
29 #include "dialogs/vlm/vlm_stream.hpp"
30 #include "dialogs/vlm/vlm_streampanel.hpp"
31
32 /*****************************************************************************
33  * Constructor.
34  *****************************************************************************/
35 VLMSliderManager::VLMSliderManager( intf_thread_t *_p_intf,
36                                     VLMBroadcastStreamPanel *_p_sp )
37 {
38     p_intf = _p_intf;
39     p_input = NULL;
40
41     p_sp = _p_sp;
42     slider = p_sp->p_slider;
43
44     b_slider_free = VLC_TRUE;
45     time_string = wxU( "0:00:00 / 0:00:00");
46 }
47
48 VLMSliderManager::~VLMSliderManager()
49 {
50 }
51
52 /*****************************************************************************
53  * Public methods.
54  *****************************************************************************/
55 void VLMSliderManager::Update()
56 {
57     /* Update the input */
58     if( p_input == NULL )
59     {
60         UpdateInput();
61
62         if( p_input )
63         {
64             slider->SetValue( 0 );
65             UpdateButtons( VLC_TRUE );
66         }
67     }
68     else if( p_input->b_dead )
69     {
70         HideSlider();
71         UpdateButtons( VLC_FALSE );
72
73         vlc_object_release( p_input );
74         p_input = NULL;
75     }
76
77     if( p_input && !p_input->b_die )
78     {
79         vlc_value_t pos;
80
81         /* Really manage the slider */
82         var_Get( p_input, "position", &pos );
83
84         if( pos.f_float > 0.0 && ! IsShown() ) ShowSlider();
85         else if( pos.f_float <= 0.0 ) HideSlider();
86
87         if( IsPlaying() && IsShown() )
88         {
89             /* Update the slider if the user isn't dragging it. */
90             if( IsFree() )
91             {
92                 char psz_time[ MSTRTIME_MAX_SIZE ];
93                 char psz_total[ MSTRTIME_MAX_SIZE ];
94                 vlc_value_t time;
95                 mtime_t i_seconds;
96
97                 /* Update the value */
98                 if( pos.f_float >= 0.0 )
99                 {
100                     i_slider_pos = (int)(SLIDER_MAX_POS * pos.f_float);
101
102                     slider->SetValue( i_slider_pos );
103
104                     var_Get( p_input, "time", &time );
105                     i_seconds = time.i_time / 1000000;
106                     secstotimestr ( psz_time, i_seconds );
107
108                     var_Get( p_input, "length",  &time );
109                     i_seconds = time.i_time / 1000000;
110                     secstotimestr ( psz_total, i_seconds );
111
112                     UpdateTime( psz_time, psz_total );
113                 }
114             }
115         }
116     }
117 }
118
119 /*****************************************************************************
120  * Private methods.
121  *****************************************************************************/
122 void VLMSliderManager::UpdateInput()
123 {
124     if( p_sp->GetStream()->p_media->i_instance == 0 )
125     {
126         p_input = NULL;
127         return;
128     }
129     /** FIXME !! */
130     p_input = p_sp->GetStream()->p_media->instance[0]->p_input;
131 }
132
133 void VLMSliderManager::UpdateButtons( vlc_bool_t b_play )
134 {
135     if( b_play )
136     {
137         p_sp->TogglePlayButton( PLAYING_S );
138     }
139     else
140     {
141         p_sp->TogglePlayButton( PAUSE_S );
142     }
143 }
144
145 vlc_bool_t VLMSliderManager::IsShown()
146 {
147     return slider->IsEnabled();
148 }
149
150 void VLMSliderManager::ShowSlider()
151 {
152     slider->Enable();
153 }
154
155 void VLMSliderManager::HideSlider()
156 {
157     slider->SetValue( 0 );
158     slider->Disable();
159     UpdateTime( "0:00:00", "0:00:00" );
160 }
161
162 vlc_bool_t VLMSliderManager::IsFree()
163 {
164     return b_slider_free;
165 }
166
167 vlc_bool_t VLMSliderManager::IsPlaying()
168 {
169     return VLC_TRUE; /* Is it really useful ? */
170 }
171
172 void VLMSliderManager::UpdateTime( char *psz_time, char *psz_total )
173 {
174     time_string = wxU(psz_time) + wxString(wxT(" / ") ) +wxU(psz_total) ;
175 }
176
177
178 void VLMSliderManager::ProcessUpdate( wxScrollEvent &event )
179 {
180
181 #ifdef WIN32
182     if( event.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
183         || event.GetEventType() == wxEVT_SCROLL_ENDSCROLL )
184     {
185 #endif
186         if( i_slider_pos != event.GetPosition() && p_input )
187         {
188             vlc_value_t pos;
189             pos.f_float = (float)event.GetPosition() / (float)SLIDER_MAX_POS;
190
191             var_Set( p_input, "position", pos );
192         }
193
194 #ifdef WIN32
195         b_slider_free = VLC_TRUE;
196     }
197     else
198     {
199         b_slider_free = VLC_FALSE;
200
201         if( p_input )
202         {
203             /* Update stream date */
204             char psz_time[ MSTRTIME_MAX_SIZE ], psz_total[ MSTRTIME_MAX_SIZE ];
205             mtime_t i_seconds;
206
207             i_seconds = var_GetTime( p_input, "length" ) / I64C(1000000 );
208             secstotimestr( psz_total, i_seconds );
209
210             i_seconds = var_GetTime( p_input, "time" ) /   I64C(1000000 );
211             secstotimestr( psz_time, i_seconds );
212
213             time_string = wxU(psz_time) + wxString(wxT(" / ") ) +wxU(psz_total) ;
214         }
215     }
216 #endif
217
218 #undef WIN32
219 }
220 #endif