* src/libvlc.c, src/libvlc.h: added a config option to disable the translation of...
[vlc.git] / modules / gui / wxwindows / timer.cpp
1 /*****************************************************************************
2  * timer.cpp : wxWindows plugin for vlc
3  *****************************************************************************
4  * Copyright (C) 2000-2001 VideoLAN
5  * $Id: timer.cpp,v 1.11 2003/03/26 00:56:22 gbazin Exp $
6  *
7  * Authors: Gildas Bazin <gbazin@netcourrier.com>
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
34 #ifdef WIN32                                                 /* mingw32 hack */
35 #undef Yield
36 #undef CreateDialog
37 #endif
38
39 /* Let vlc take care of the i18n stuff */
40 #define WXINTL_NO_GETTEXT_MACRO
41
42 #include <wx/wxprec.h>
43 #include <wx/wx.h>
44 #include <wx/timer.h>
45
46 #include <vlc/intf.h>
47
48 #include "wxwindows.h"
49
50 void DisplayStreamDate( wxControl *, intf_thread_t *, int );
51
52 /*****************************************************************************
53  * Constructor.
54  *****************************************************************************/
55 Timer::Timer( intf_thread_t *_p_intf, Interface *_p_main_interface )
56 {
57     p_intf = _p_intf;
58     p_main_interface = _p_main_interface;
59     i_old_playing_status = PAUSE_S;
60
61     Start( 100 /*milliseconds*/, wxTIMER_CONTINUOUS );
62 }
63
64 Timer::~Timer()
65 {
66 }
67
68 /*****************************************************************************
69  * Private methods.
70  *****************************************************************************/
71 /*****************************************************************************
72  * wxModeManage: actualise the aspect of the interface whenever the input
73  * changes.
74  *****************************************************************************
75  * The lock has to be taken before you call the function.
76  *****************************************************************************/
77 static int wxModeManage( intf_thread_t * p_intf )
78 {
79     return 0;
80 }
81
82 /*****************************************************************************
83  * wxSetupMenus: function that generates title/chapter/audio/subpic
84  * menus with help from preceding functions
85  *****************************************************************************
86  * Function called with the lock on stream
87  *****************************************************************************/
88 static int wxSetupMenus( intf_thread_t * p_intf )
89 {
90     return 0;
91 }
92
93 /*****************************************************************************
94  * Manage: manage main thread messages
95  *****************************************************************************
96  * In this function, called approx. 10 times a second, we check what the
97  * main program wanted to tell us.
98  *****************************************************************************/
99 void Timer::Notify()
100 {
101     vlc_mutex_lock( &p_intf->change_lock );
102
103     /* If the "display popup" flag has changed */
104     if( p_intf->b_menu_change )
105     {
106         p_main_interface->p_popup_menu =
107             new PopupMenu( p_intf, p_main_interface );
108         p_intf->b_menu_change = 0;
109     }
110
111     /* Update the log window */
112     p_intf->p_sys->p_messages_window->UpdateLog();
113
114     /* Update the playlist */
115     p_intf->p_sys->p_playlist_window->Manage();
116
117     /* Update the input */
118     if( p_intf->p_sys->p_input == NULL )
119     {
120         p_intf->p_sys->p_input = (input_thread_t *)vlc_object_find( p_intf,
121                                                        VLC_OBJECT_INPUT,
122                                                        FIND_ANYWHERE );
123         /* Show slider */
124         if(p_intf->p_sys->p_input)
125         {
126             p_main_interface->frame_sizer->Add(
127                 p_main_interface->slider_frame, 1, wxGROW, 0 );
128             p_main_interface->slider_frame->Show();
129             p_main_interface->frame_sizer->Layout();
130             p_main_interface->frame_sizer->Fit( p_main_interface );
131             p_main_interface->statusbar->SetStatusText(
132                 p_intf->p_sys->p_input->psz_source, 1 );
133
134             p_main_interface->TogglePlayButton( PLAYING_S );
135             i_old_playing_status = PLAYING_S;
136         }
137     }
138     else if( p_intf->p_sys->p_input->b_dead )
139     {
140         /* Hide slider */
141         if(p_intf->p_sys->p_input)
142         {
143             p_main_interface->slider_frame->Hide();
144             p_main_interface->frame_sizer->Remove(
145                 p_main_interface->slider_frame );
146             p_main_interface->frame_sizer->Layout();
147             p_main_interface->frame_sizer->Fit( p_main_interface );
148
149             p_main_interface->TogglePlayButton( PAUSE_S );
150             i_old_playing_status = PAUSE_S;
151         }
152
153         p_main_interface->statusbar->SetStatusText( "", 1 );
154
155         vlc_object_release( p_intf->p_sys->p_input );
156         p_intf->p_sys->p_input = NULL;
157     }
158
159     if( p_intf->p_sys->p_input )
160     {
161         input_thread_t *p_input = p_intf->p_sys->p_input;
162
163         vlc_mutex_lock( &p_input->stream.stream_lock );
164
165         if( !p_input->b_die )
166         {
167             /* New input or stream map change */
168             p_intf->p_sys->b_playing = 1;
169 #if 0
170             if( p_input->stream.b_changed )
171             {
172                 wxModeManage( p_intf );
173                 wxSetupMenus( p_intf );
174                 p_intf->p_sys->b_playing = 1;
175
176                 p_main_interface->TogglePlayButton( PLAYING_S );
177                 i_old_playing_status = PLAYING_S;
178             }
179 #endif
180
181             /* Manage the slider */
182             if( p_input->stream.b_seekable && p_intf->p_sys->b_playing )
183             {
184
185                 stream_position_t position;
186
187                 /* Update the slider if the user isn't dragging it. */
188                 if( p_intf->p_sys->b_slider_free )
189                 {
190                     /* Update the value */
191                     vlc_mutex_unlock( &p_input->stream.stream_lock );
192                     input_Tell( p_input, &position );
193                     vlc_mutex_lock( &p_input->stream.stream_lock );
194                     p_intf->p_sys->i_slider_pos =
195                         ( SLIDER_MAX_POS * position.i_tell ) / position.i_size;
196
197                     p_main_interface->slider->SetValue(
198                         p_intf->p_sys->i_slider_pos );
199
200                     DisplayStreamDate( p_main_interface->slider_box,
201                                        p_intf,
202                                        p_intf->p_sys->i_slider_pos );
203                 }
204             }
205
206             if( p_intf->p_sys->i_part !=
207                 p_input->stream.p_selected_area->i_part )
208             {
209                 p_intf->p_sys->b_chapter_update = 1;
210                 wxSetupMenus( p_intf );
211             }
212
213             /* Manage Playing status */
214             if( i_old_playing_status != p_input->stream.control.i_status )
215             {
216                 if( p_input->stream.control.i_status == PAUSE_S )
217                 {
218                     p_main_interface->TogglePlayButton( PAUSE_S );
219                 }
220                 else
221                 {
222                     p_main_interface->TogglePlayButton( PLAYING_S );
223                 }
224                 i_old_playing_status = p_input->stream.control.i_status;
225             }
226         }
227
228         vlc_mutex_unlock( &p_input->stream.stream_lock );
229     }
230     else if( p_intf->p_sys->b_playing && !p_intf->b_die )
231     {
232         wxModeManage( p_intf );
233         p_intf->p_sys->b_playing = 0;
234         p_main_interface->TogglePlayButton( PAUSE_S );
235         i_old_playing_status = PAUSE_S;
236     }
237
238     if( p_intf->b_die )
239     {
240         vlc_mutex_unlock( &p_intf->change_lock );
241
242         /* Prepare to die, young Skywalker */
243         p_main_interface->Close(TRUE);
244         return;
245     }
246
247     vlc_mutex_unlock( &p_intf->change_lock );
248 }
249
250 /*****************************************************************************
251  * DisplayStreamDate: display stream date
252  *****************************************************************************
253  * This function displays the current date related to the position in
254  * the stream. It is called whenever the slider changes its value.
255  * The lock has to be taken before you call the function.
256  *****************************************************************************/
257 void DisplayStreamDate( wxControl *p_slider_frame, intf_thread_t * p_intf ,
258                         int i_pos )
259 {
260     if( p_intf->p_sys->p_input )
261     {
262 #define p_area p_intf->p_sys->p_input->stream.p_selected_area
263         char psz_time[ OFFSETTOTIME_MAX_SIZE ];
264
265         p_slider_frame->SetLabel(
266             input_OffsetToTime( p_intf->p_sys->p_input,
267                                 psz_time,
268                                 p_area->i_size * i_pos / SLIDER_MAX_POS ) );
269 #undef p_area
270      }
271 }