* ./modules/gui/kde/kde.cpp: the interface rc file defaults to the one in
[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.10 2003/01/28 21:08:29 sam 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
60     Start( 100 /*milliseconds*/, wxTIMER_CONTINUOUS );
61 }
62
63 Timer::~Timer()
64 {
65 }
66
67 /*****************************************************************************
68  * Private methods.
69  *****************************************************************************/
70 /*****************************************************************************
71  * wxModeManage: actualise the aspect of the interface whenever the input
72  * changes.
73  *****************************************************************************
74  * The lock has to be taken before you call the function.
75  *****************************************************************************/
76 static int wxModeManage( intf_thread_t * p_intf )
77 {
78     return 0;
79 }
80
81 /*****************************************************************************
82  * wxSetupMenus: function that generates title/chapter/audio/subpic
83  * menus with help from preceding functions
84  *****************************************************************************
85  * Function called with the lock on stream
86  *****************************************************************************/
87 static int wxSetupMenus( intf_thread_t * p_intf )
88 {
89     return 0;
90 }
91
92 /*****************************************************************************
93  * Manage: manage main thread messages
94  *****************************************************************************
95  * In this function, called approx. 10 times a second, we check what the
96  * main program wanted to tell us.
97  *****************************************************************************/
98 void Timer::Notify()
99 {
100     vlc_mutex_lock( &p_intf->change_lock );
101
102     /* If the "display popup" flag has changed */
103     if( p_intf->b_menu_change )
104     {
105         p_main_interface->p_popup_menu =
106             new PopupMenu( p_intf, p_main_interface );
107         p_intf->b_menu_change = 0;
108     }
109
110     /* Update the log window */
111     p_intf->p_sys->p_messages_window->UpdateLog();
112
113     /* Update the playlist */
114     p_intf->p_sys->p_playlist_window->Manage();
115
116     /* Update the input */
117     if( p_intf->p_sys->p_input == NULL )
118     {
119         p_intf->p_sys->p_input = (input_thread_t *)vlc_object_find( p_intf,
120                                                        VLC_OBJECT_INPUT,
121                                                        FIND_ANYWHERE );
122         /* Show slider */
123         if(p_intf->p_sys->p_input)
124         {
125             p_main_interface->frame_sizer->Add(
126                 p_main_interface->slider_frame, 1, wxGROW, 0 );
127             p_main_interface->slider_frame->Show();
128             p_main_interface->frame_sizer->Layout();
129             p_main_interface->frame_sizer->Fit( p_main_interface );
130             p_main_interface->statusbar->SetStatusText(
131                 p_intf->p_sys->p_input->psz_source, 1 );
132         }
133     }
134     else if( p_intf->p_sys->p_input->b_dead )
135     {
136         /* Hide slider */
137         if(p_intf->p_sys->p_input)
138         {
139             p_main_interface->slider_frame->Hide();
140             p_main_interface->frame_sizer->Remove(
141                 p_main_interface->slider_frame );
142             p_main_interface->frame_sizer->Layout();
143             p_main_interface->frame_sizer->Fit( p_main_interface );
144         }
145
146         p_main_interface->statusbar->SetStatusText( "", 1 );
147
148         vlc_object_release( p_intf->p_sys->p_input );
149         p_intf->p_sys->p_input = NULL;
150     }
151
152     if( p_intf->p_sys->p_input )
153     {
154         input_thread_t *p_input = p_intf->p_sys->p_input;
155
156         vlc_mutex_lock( &p_input->stream.stream_lock );
157
158         if( !p_input->b_die )
159         {
160             /* New input or stream map change */
161             if( p_input->stream.b_changed )
162             {
163                 wxModeManage( p_intf );
164                 wxSetupMenus( p_intf );
165                 p_intf->p_sys->b_playing = 1;
166             }
167
168             /* Manage the slider */
169             if( p_input->stream.b_seekable && p_intf->p_sys->b_playing )
170             {
171
172                 stream_position_t position;
173
174                 /* Update the slider if the user isn't dragging it. */
175                 if( p_intf->p_sys->b_slider_free )
176                 {
177                     /* Update the value */
178                     vlc_mutex_unlock( &p_input->stream.stream_lock );
179                     input_Tell( p_input, &position );
180                     vlc_mutex_lock( &p_input->stream.stream_lock );
181                     p_intf->p_sys->i_slider_pos =
182                         ( SLIDER_MAX_POS * position.i_tell ) / position.i_size;
183
184                     p_main_interface->slider->SetValue(
185                         p_intf->p_sys->i_slider_pos );
186
187                     DisplayStreamDate( p_main_interface->slider_box,
188                                        p_intf,
189                                        p_intf->p_sys->i_slider_pos );
190                 }
191             }
192
193             if( p_intf->p_sys->i_part !=
194                 p_input->stream.p_selected_area->i_part )
195             {
196                 p_intf->p_sys->b_chapter_update = 1;
197                 wxSetupMenus( p_intf );
198             }
199         }
200
201         vlc_mutex_unlock( &p_input->stream.stream_lock );
202     }
203     else if( p_intf->p_sys->b_playing && !p_intf->b_die )
204     {
205         wxModeManage( p_intf );
206         p_intf->p_sys->b_playing = 0;
207     }
208
209     if( p_intf->b_die )
210     {
211         vlc_mutex_unlock( &p_intf->change_lock );
212
213         /* Prepare to die, young Skywalker */
214         p_main_interface->Close(TRUE);
215         return;
216     }
217
218     vlc_mutex_unlock( &p_intf->change_lock );
219 }
220
221 /*****************************************************************************
222  * DisplayStreamDate: display stream date
223  *****************************************************************************
224  * This function displays the current date related to the position in
225  * the stream. It is called whenever the slider changes its value.
226  * The lock has to be taken before you call the function.
227  *****************************************************************************/
228 void DisplayStreamDate( wxControl *p_slider_frame, intf_thread_t * p_intf ,
229                         int i_pos )
230 {
231     if( p_intf->p_sys->p_input )
232     {
233 #define p_area p_intf->p_sys->p_input->stream.p_selected_area
234         char psz_time[ OFFSETTOTIME_MAX_SIZE ];
235
236         p_slider_frame->SetLabel(
237             input_OffsetToTime( p_intf->p_sys->p_input,
238                                 psz_time,
239                                 p_area->i_size * i_pos / SLIDER_MAX_POS ) );
240 #undef p_area
241      }
242 }