]> git.sesse.net Git - vlc/blob - modules/gui/wince/timer.cpp
Remove _GNU_SOURCE and string.h too
[vlc] / modules / gui / wince / timer.cpp
1 /*****************************************************************************
2  * timer.cpp : WinCE gui plugin for VLC
3  *****************************************************************************
4  * Copyright (C) 2000-2003 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Marodon Cedric <cedric_marodon@yahoo.fr>
8  *          Gildas Bazin <gbazin@videolan.org>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23  *****************************************************************************/
24
25 /*****************************************************************************
26  * Preamble
27  *****************************************************************************/
28 #include <stdio.h>
29 #include <vlc/vlc.h>
30 #include <vlc_aout.h>
31 #include <vlc_interface.h>
32
33 #include "wince.h"
34
35 #include <commctrl.h>
36
37 /* Callback prototype */
38 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
39                         vlc_value_t old_val, vlc_value_t new_val, void * );
40
41 /*****************************************************************************
42  * Constructor.
43  *****************************************************************************/
44 Timer::Timer( intf_thread_t *_p_intf, HWND hwnd, Interface *_p_main_interface)
45 {
46     p_intf = _p_intf;
47     p_main_interface = _p_main_interface;
48     i_old_playing_status = PAUSE_S;
49     i_old_rate = INPUT_RATE_DEFAULT;
50
51     /* Register callback for the intf-popupmenu variable */
52     playlist_t *p_playlist =
53         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
54                                        FIND_ANYWHERE );
55     if( p_playlist != NULL )
56     {
57         var_AddCallback( p_playlist, "intf-popupmenu", PopupMenuCB, p_intf );
58         vlc_object_release( p_playlist );
59     }
60
61     SetTimer( hwnd, 1, 200 /*milliseconds*/, NULL );
62 }
63
64 Timer::~Timer()
65 {
66     /* Unregister callback */
67     playlist_t *p_playlist =
68         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
69                                        FIND_ANYWHERE );
70     if( p_playlist != NULL )
71     {
72         var_DelCallback( p_playlist, "intf-popupmenu", PopupMenuCB, p_intf );
73         vlc_object_release( p_playlist );
74     }
75 }
76
77 /*****************************************************************************
78  * Private methods.
79  *****************************************************************************/
80
81 /*****************************************************************************
82  * Manage: manage main thread messages
83  *****************************************************************************
84  * In this function, called approx. 10 times a second, we check what the
85  * main program wanted to tell us.
86  *****************************************************************************/
87 void Timer::Notify( void )
88 {
89     vlc_value_t val;
90     char *shortname;
91
92     vlc_mutex_lock( &p_intf->change_lock );
93
94     /* Update the input */
95     if( p_intf->p_sys->p_input == NULL )
96     {
97         p_intf->p_sys->p_input =
98             (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
99                                                FIND_ANYWHERE );
100
101         /* Show slider */
102         if( p_intf->p_sys->p_input )
103         {
104             ShowWindow( p_main_interface->hwndSlider, SW_SHOW );
105             ShowWindow( p_main_interface->hwndLabel, SW_SHOW );
106             ShowWindow( p_main_interface->hwndVol, SW_SHOW );
107
108             // only for local file, check if works well with net url
109             shortname = strrchr( p_intf->p_sys->p_input->input.p_item->psz_name, '\\' );
110             if (! shortname)
111                 shortname = p_intf->p_sys->p_input->input.p_item->psz_name;
112             else shortname++;
113                         
114             SendMessage( p_main_interface->hwndSB, SB_SETTEXT, 
115                          (WPARAM) 0, (LPARAM)_FROMMB(shortname) );
116
117             p_main_interface->TogglePlayButton( PLAYING_S );
118             i_old_playing_status = PLAYING_S;
119         }
120     }
121     else if( p_intf->p_sys->p_input->b_dead )
122     {
123         /* Hide slider */
124         ShowWindow( p_main_interface->hwndSlider, SW_HIDE);
125         ShowWindow( p_main_interface->hwndLabel, SW_HIDE);
126         ShowWindow( p_main_interface->hwndVol, SW_HIDE);
127
128         p_main_interface->TogglePlayButton( PAUSE_S );
129         i_old_playing_status = PAUSE_S;
130
131         SendMessage( p_main_interface->hwndSB, SB_SETTEXT, 
132                      (WPARAM) 0, (LPARAM)(LPCTSTR) TEXT(""));
133
134         vlc_object_release( p_intf->p_sys->p_input );
135         p_intf->p_sys->p_input = NULL;
136     }
137
138     if( p_intf->p_sys->p_input )
139     {
140         input_thread_t *p_input = p_intf->p_sys->p_input;
141
142         if( !p_input->b_die )
143         {
144             /* New input or stream map change */
145             p_intf->p_sys->b_playing = 1;
146
147             /* Manage the slider */
148             if( /*p_input->stream.b_seekable &&*/ p_intf->p_sys->b_playing )
149             {
150                 /* Update the slider if the user isn't dragging it. */
151                 if( p_intf->p_sys->b_slider_free )
152                 {
153                     vlc_value_t pos;
154                     char psz_time[ MSTRTIME_MAX_SIZE ];
155                     vlc_value_t time;
156                     mtime_t i_seconds;
157
158                     /* Update the value */
159                     var_Get( p_input, "position", &pos );
160                     if( pos.f_float >= 0.0 )
161                     {
162                         p_intf->p_sys->i_slider_pos =
163                             (int)(SLIDER_MAX_POS * pos.f_float);
164
165                         SendMessage( p_main_interface->hwndSlider, TBM_SETPOS, 
166                                      1, p_intf->p_sys->i_slider_pos );
167
168                         var_Get( p_intf->p_sys->p_input, "time", &time );
169                         i_seconds = time.i_time / 1000000;
170                         secstotimestr ( psz_time, i_seconds );
171
172                         SendMessage( p_main_interface->hwndLabel, WM_SETTEXT, 
173                                      (WPARAM)1, (LPARAM)_FROMMB(psz_time) );
174                     }
175                 }
176             }
177
178             /* Take care of the volume, etc... */
179             p_main_interface->Update();
180
181             /* Manage Playing status */
182             var_Get( p_input, "state", &val );
183             if( i_old_playing_status != val.i_int )
184             {
185                 if( val.i_int == PAUSE_S )
186                 {
187                     p_main_interface->TogglePlayButton( PAUSE_S );
188                 }
189                 else
190                 {
191                     p_main_interface->TogglePlayButton( PLAYING_S );
192                 }
193                 i_old_playing_status = val.i_int;
194             }
195
196             /* Manage Speed status */
197             var_Get( p_input, "rate", &val );
198             if( i_old_rate != val.i_int )
199             {
200                 TCHAR psz_text[15];
201                 _stprintf( psz_text + 2, _T("x%.2f"), 1000.0 / val.i_int );
202                 psz_text[0] = psz_text[1] = _T('\t');
203
204                 SendMessage( p_main_interface->hwndSB, SB_SETTEXT, 
205                              (WPARAM) 1, (LPARAM)(LPCTSTR) psz_text );
206
207                 i_old_rate = val.i_int;
208             }
209         }
210     }
211     else if( p_intf->p_sys->b_playing && !intf_ShouldDie( p_intf ) )
212     {
213         p_intf->p_sys->b_playing = 0;
214         p_main_interface->TogglePlayButton( PAUSE_S );
215         i_old_playing_status = PAUSE_S;
216     }
217
218     if( intf_ShouldDie( p_intf ) )
219     {
220         vlc_mutex_unlock( &p_intf->change_lock );
221
222         /* Prepare to die, young Skywalker */
223 /*        p_main_interface->Close(TRUE);*/
224         return;
225     }
226
227     vlc_mutex_unlock( &p_intf->change_lock );
228 }
229
230 /*****************************************************************************
231  * PopupMenuCB: callback triggered by the intf-popupmenu playlist variable.
232  *  We don't show the menu directly here because we don't want the
233  *  caller to block for a too long time.
234  *****************************************************************************/
235 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
236                         vlc_value_t old_val, vlc_value_t new_val, void *param )
237 {
238     intf_thread_t *p_intf = (intf_thread_t *)param;
239
240     if( p_intf->p_sys->pf_show_dialog )
241     {
242         p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU,
243                                        new_val.b_bool, 0 );
244     }
245
246     return VLC_SUCCESS;
247 }