* added a wxwindows interface using the wxWindows cross-platform GUI framework.
[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.1 2002/11/18 13:02:16 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 #include <vlc/intf.h>
34
35 /* Let wxWindows take care of the i18n stuff */
36 #undef _
37
38 #ifdef WIN32                                                 /* mingw32 hack */
39 #undef Yield()
40 #undef CreateDialog()
41 #endif
42
43 #include <wx/wxprec.h>
44 #include <wx/wx.h>
45 #include <wx/timer.h>
46
47 #include "wxwindows.h"
48
49 /*****************************************************************************
50  * Constructor.
51  *****************************************************************************/
52 Timer::Timer( intf_thread_t *_p_intf, Interface *_p_main_interface )
53 {
54     p_intf = _p_intf;
55     p_main_interface = _p_main_interface;
56
57     Start( 100 /*milliseconds*/, wxTIMER_CONTINUOUS );
58 }
59
60 Timer::~Timer()
61 {
62 }
63
64 /*****************************************************************************
65  * Private methods.
66  *****************************************************************************/
67 /*****************************************************************************
68  * wxModeManage: actualise the aspect of the interface whenever the input
69  * changes.
70  *****************************************************************************
71  * The lock has to be taken before you call the function.
72  *****************************************************************************/
73 static int wxModeManage( intf_thread_t * p_intf )
74 {
75     return 0;
76 }
77
78 /*****************************************************************************
79  * wxSetupMenus: function that generates title/chapter/audio/subpic
80  * menus with help from preceding functions
81  *****************************************************************************
82  * Function called with the lock on stream
83  *****************************************************************************/
84 static int wxSetupMenus( intf_thread_t * p_intf )
85 {
86     return 0;
87 }
88
89 /*****************************************************************************
90  * Manage: manage main thread messages
91  *****************************************************************************
92  * In this function, called approx. 10 times a second, we check what the
93  * main program wanted to tell us.
94  *****************************************************************************/
95 void Timer::Notify()
96 {
97     int i_start, i_stop;
98
99     vlc_mutex_lock( &p_intf->change_lock );
100
101     /* If the "display popup" flag has changed */
102     if( p_intf->b_menu_change )
103     {
104         p_intf->b_menu_change = 0;
105     }
106
107     /* Update the log window */
108     vlc_mutex_lock( p_intf->p_sys->p_sub->p_lock );
109     i_stop = *p_intf->p_sys->p_sub->pi_stop;
110     vlc_mutex_unlock( p_intf->p_sys->p_sub->p_lock );
111
112     if( p_intf->p_sys->p_sub->i_start != i_stop )
113     {
114     }
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->slider->Show();
126             p_main_interface->statusbar->SetStatusText(
127                 p_intf->p_sys->p_input->psz_source, 1 );
128         }
129     }
130     else if( p_intf->p_sys->p_input->b_dead )
131     {
132         /* Hide slider */
133         if(p_intf->p_sys->p_input)
134             p_main_interface->slider->Hide();
135
136         p_main_interface->statusbar->SetStatusText( "", 1 );
137
138         vlc_object_release( p_intf->p_sys->p_input );
139         p_intf->p_sys->p_input = NULL;
140     }
141
142     if( p_intf->p_sys->p_input )
143     {
144         input_thread_t *p_input = p_intf->p_sys->p_input;
145
146         vlc_mutex_lock( &p_input->stream.stream_lock );
147
148         if( !p_input->b_die )
149         {
150             /* New input or stream map change */
151             if( p_input->stream.b_changed )
152             {
153                 wxModeManage( p_intf );
154                 wxSetupMenus( p_intf );
155                 p_intf->p_sys->b_playing = 1;
156             }
157
158             /* Manage the slider */
159             if( p_input->stream.b_seekable && p_intf->p_sys->b_playing )
160             {
161
162                 stream_position_t position;
163
164                 /* If the user hasn't touched the slider since the last time,
165                  * then the input can safely change it */
166                 if( p_intf->p_sys->i_slider_pos ==
167                     p_intf->p_sys->i_slider_oldpos )
168                 {
169                     /* Update the value */
170                     vlc_mutex_unlock( &p_input->stream.stream_lock );
171                     input_Tell( p_input, &position );
172                     vlc_mutex_lock( &p_input->stream.stream_lock );
173                     p_intf->p_sys->i_slider_oldpos =
174                         ( 100 * position.i_tell ) / position.i_size;
175
176                     if( p_intf->p_sys->i_slider_pos !=
177                         p_intf->p_sys->i_slider_oldpos )
178                     {
179                         p_intf->p_sys->i_slider_pos =
180                             p_intf->p_sys->i_slider_oldpos;
181
182                         p_main_interface->slider->SetValue(
183                             p_intf->p_sys->i_slider_pos );
184                     }
185                 }
186
187                 /* Otherwise, send message to the input if the user has
188                  * finished dragging the slider */
189                 else if( p_intf->p_sys->b_slider_free )
190                 {
191                     /* release the lock to be able to seek */
192                     vlc_mutex_unlock( &p_input->stream.stream_lock );
193                     input_Seek( p_input, p_intf->p_sys->i_slider_pos,
194                                 INPUT_SEEK_PERCENT | INPUT_SEEK_SET );
195                     vlc_mutex_lock( &p_input->stream.stream_lock );
196
197                     /* Update the old value */
198                     p_intf->p_sys->i_slider_oldpos =
199                         p_intf->p_sys->i_slider_pos;
200                 }
201             }
202
203             if( p_intf->p_sys->i_part !=
204                 p_input->stream.p_selected_area->i_part )
205             {
206                 p_intf->p_sys->b_chapter_update = 1;
207                 wxSetupMenus( p_intf );
208             }
209         }
210
211         vlc_mutex_unlock( &p_input->stream.stream_lock );
212     }
213     else if( p_intf->p_sys->b_playing && !p_intf->b_die )
214     {
215         wxModeManage( p_intf );
216         p_intf->p_sys->b_playing = 0;
217     }
218
219     vlc_mutex_unlock( &p_intf->change_lock );
220 }