]> git.sesse.net Git - vlc/blob - modules/gui/wxwidgets/slider_manager.cpp
p( vlc.getInterfaces().getInterface( "wxwidgets" ).isBroken() ) = 1/2
[vlc] / modules / gui / wxwidgets / slider_manager.cpp
1 /*****************************************************************************
2  * slider_manager.cpp : Manage an input slider
3  *****************************************************************************
4  * Copyright (C) 2000-2005 the VideoLAN team
5  * $Id: timer.cpp 11981 2005-08-03 15:03:23Z xtophe $
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., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #include <stdlib.h>                                      /* malloc(), free() */
28 #include <errno.h>                                                 /* ENOMEM */
29 #include <string.h>                                            /* strerror() */
30 #include <stdio.h>
31
32 #include <vlc/vlc.h>
33 #include <vlc/aout.h>
34 #include <vlc/intf.h>
35
36 #include "vlc_meta.h"
37
38 #include "wxwidgets.hpp"
39
40 #include "slider_manager.hpp"
41
42 /*****************************************************************************
43  * Constructor.
44  *****************************************************************************/
45 SliderManager::SliderManager( intf_thread_t *_p_intf )
46 {
47     p_intf = _p_intf;
48     p_input = NULL;
49     i_old_playing_status = PAUSE_S;
50 }
51
52 SliderManager::~SliderManager()
53 {
54     vlc_mutex_lock( &p_intf->change_lock );
55     if( p_intf->p_sys->p_input ) vlc_object_release( p_intf->p_sys->p_input );
56     p_intf->p_sys->p_input = NULL;
57     vlc_mutex_unlock( &p_intf->change_lock );
58 }
59
60 /*****************************************************************************
61  * Private methods.
62  *****************************************************************************/
63 void SliderManager::Update()
64 {
65     /* Update the input */
66     if( p_input == NULL )
67     {
68         UpdateInput();
69         if( p_input )
70         {
71             _slider->SetValue( 0 );
72             UpdateNowPlaying();
73
74             UpdateButtons( VLC_TRUE );
75
76             i_old_playing_status = PLAYING_S;
77         }
78     }
79     else if( p_input->b_dead )
80     {
81         HideControls();
82         HideSlider();
83
84         UpdateButtons( VLC_FALSE );
85
86         i_old_playing_status = PAUSE_S;
87
88         vlc_object_release( p_input );
89         p_input = NULL;
90     }
91
92     if( p_input )
93     {
94         if( !p_input->b_die )
95         {
96             vlc_value_t pos;
97
98             DontHide();
99
100             UpdateNowPlaying();
101
102             /* Really manage the slider */
103             var_Get( p_input, "position", &pos );
104
105             UpdateDiscButtons();
106
107             if( pos.f_float > 0.0 && ! IsShown() )
108             {
109                  ShowSlider();
110             }
111             else if( pos.f_float <= 0.0 )
112             {
113                 HideSlider();
114             }
115
116             if( IsPlaying() && IsShown() )
117             {
118                 /* Update the slider if the user isn't dragging it. */
119                 if( IsFree() )
120                 {
121                     char psz_time[ MSTRTIME_MAX_SIZE ];
122                     char psz_total[ MSTRTIME_MAX_SIZE ];
123                     vlc_value_t time;
124                     mtime_t i_seconds;
125
126                     /* Update the value */
127                     if( pos.f_float >= 0.0 )
128                     {
129                         i_slider_pos = (int)(SLIDER_MAX_POS * pos.f_float);
130
131                         _slider->SetValue( i_slider_pos );
132
133                         var_Get( p_input, "time", &time );
134                         i_seconds = time.i_time / 1000000;
135                         secstotimestr ( psz_time, i_seconds );
136
137                         var_Get( p_input, "length",  &time );
138                         i_seconds = time.i_time / 1000000;
139                         secstotimestr ( psz_total, i_seconds );
140
141                         UpdateTime( psz_time, psz_total );
142 //                        p_main_interface->statusbar->SetStatusText(
143 //                            wxU(psz_time) + wxString(wxT(" / ")) +
144 //                            wxU(psz_total), 0 );
145                     }
146                 }
147             }
148         }
149     }
150 }