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