]> git.sesse.net Git - vlc/blob - modules/gui/wince/timer.cpp
* modules/gui/wince: WinCE build fixes.
[vlc] / modules / gui / wince / timer.cpp
1 /*****************************************************************************
2  * timer.cpp : WinCE gui plugin for VLC
3  *****************************************************************************
4  * Copyright (C) 2000-2003 VideoLAN
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., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
23  *****************************************************************************/
24
25 /*****************************************************************************
26  * Preamble
27  *****************************************************************************/
28 #include <stdlib.h>                                      /* malloc(), free() */
29 #include <string.h>                                            /* strerror() */
30 #include <stdio.h>
31 #include <vlc/vlc.h>
32 #include <vlc/aout.h>
33 #include <vlc/intf.h>
34
35 #include "wince.h"
36
37 #include <commctrl.h>
38
39 /* Callback prototype */
40 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
41                         vlc_value_t old_val, vlc_value_t new_val, void *param );
42
43 /*****************************************************************************
44  * Constructor.
45  *****************************************************************************/
46 Timer::Timer( intf_thread_t *_p_intf, HWND hwnd, Interface *_p_main_interface)//, Interface *_p_main_interface )
47 {
48     p_intf = _p_intf;
49     p_main_interface = _p_main_interface;
50     i_old_playing_status = PAUSE_S;
51     i_old_rate = INPUT_RATE_DEFAULT;
52
53     /* Register callback for the intf-popupmenu variable */
54     playlist_t *p_playlist =
55         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
56                                        FIND_ANYWHERE );
57     if( p_playlist != NULL )
58     {
59         var_AddCallback( p_playlist, "intf-popupmenu", PopupMenuCB, p_intf );
60         vlc_object_release( p_playlist );
61     }
62
63     SetTimer( hwnd, 1, 200 /*milliseconds*/, NULL );
64 }
65
66 Timer::~Timer()
67 {
68     /* Unregister callback */
69     playlist_t *p_playlist =
70         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
71                                        FIND_ANYWHERE );
72     if( p_playlist != NULL )
73     {
74         var_DelCallback( p_playlist, "intf-popupmenu", PopupMenuCB, p_intf );
75         vlc_object_release( p_playlist );
76     }
77 }
78
79 /*****************************************************************************
80  * Private methods.
81  *****************************************************************************/
82
83 /*****************************************************************************
84  * Manage: manage main thread messages
85  *****************************************************************************
86  * In this function, called approx. 10 times a second, we check what the
87  * main program wanted to tell us.
88  *****************************************************************************/
89 void Timer::Notify( void )
90 {
91     int size;
92     vlc_value_t val;
93     char *shortname;
94     LPWSTR wUnicode;
95
96     vlc_mutex_lock( &p_intf->change_lock );
97
98     /* Update the input */
99     if( p_intf->p_sys->p_input == NULL )
100     {
101         p_intf->p_sys->p_input =
102             (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
103                                                FIND_ANYWHERE );
104
105         /* Show slider */
106         if( p_intf->p_sys->p_input )
107         {
108             ShowWindow( p_main_interface->hwndSlider, SW_SHOW);
109             ShowWindow( p_main_interface->hwndLabel, SW_SHOW);
110             ShowWindow( p_main_interface->hwndVol, SW_SHOW);
111
112             // only for local file, check if works well with net url
113             shortname = strrchr( p_intf->p_sys->p_input->input.p_item->psz_name, '\\' );
114             if (! shortname)
115                 shortname = p_intf->p_sys->p_input->input.p_item->psz_name;
116             else
117                 shortname++;
118                         
119             size = MultiByteToWideChar (CP_ACP, 0, shortname, -1, NULL, 0);
120             wUnicode = new WCHAR[size+1];
121             MultiByteToWideChar (CP_ACP, 0, shortname, -1, wUnicode + 1, size) ;
122             wUnicode[0] = L'\t';
123
124             SendMessage( p_main_interface->hwndSB, SB_SETTEXT, 
125                          (WPARAM) 0, (LPARAM)(LPCTSTR) wUnicode);
126             free( wUnicode );
127
128             p_main_interface->TogglePlayButton( PLAYING_S );
129             i_old_playing_status = PLAYING_S;
130
131             /* Take care of the volume */
132             audio_volume_t i_volume;
133             aout_VolumeGet( p_intf, &i_volume );                        
134             SendMessage( p_main_interface->hwndVol, TBM_SETPOS, 1,
135                          200 - (i_volume * 200 * 2 / AOUT_VOLUME_MAX ) );
136         }
137     }
138     else if( p_intf->p_sys->p_input->b_dead )
139     {
140         /* Hide slider */
141         ShowWindow( p_main_interface->hwndSlider, SW_HIDE);
142         ShowWindow( p_main_interface->hwndLabel, SW_HIDE);
143         ShowWindow( p_main_interface->hwndVol, SW_HIDE);
144
145         p_main_interface->TogglePlayButton( PAUSE_S );
146         i_old_playing_status = PAUSE_S;
147
148         SendMessage( p_main_interface->hwndSB, SB_SETTEXT, 
149                      (WPARAM) 0, (LPARAM)(LPCTSTR) TEXT(""));
150
151         vlc_object_release( p_intf->p_sys->p_input );
152         p_intf->p_sys->p_input = NULL;
153     }
154
155     if( p_intf->p_sys->p_input )
156     {
157         input_thread_t *p_input = p_intf->p_sys->p_input;
158
159         if( !p_input->b_die )
160         {
161             /* New input or stream map change */
162             p_intf->p_sys->b_playing = 1;
163
164             /* Manage the slider */
165             if( /*p_input->stream.b_seekable &&*/ p_intf->p_sys->b_playing )
166             {
167                 /* Update the slider if the user isn't dragging it. */
168                 if( p_intf->p_sys->b_slider_free )
169                 {
170                     vlc_value_t pos;
171                     char psz_time[ MSTRTIME_MAX_SIZE ];
172                     vlc_value_t time;
173                     mtime_t i_seconds;
174
175                     /* Update the value */
176                     var_Get( p_input, "position", &pos );
177                     if( pos.f_float >= 0.0 )
178                     {
179                         p_intf->p_sys->i_slider_pos =
180                             (int)(SLIDER_MAX_POS * pos.f_float);
181
182                         SendMessage( p_main_interface->hwndSlider,TBM_SETPOS, 
183                                      1, p_intf->p_sys->i_slider_pos );
184
185                         var_Get( p_intf->p_sys->p_input, "time", &time );
186                         i_seconds = time.i_time / 1000000;
187
188                         secstotimestr ( psz_time, i_seconds );
189
190                         size = MultiByteToWideChar (CP_ACP, 0, psz_time, -1, NULL, 0);
191                         wUnicode = new WCHAR[size];
192                         MultiByteToWideChar (CP_ACP, 0, psz_time, -1, wUnicode, size) ;
193                         SendMessage( p_main_interface->hwndLabel, WM_SETTEXT, 
194                                      (WPARAM) 1, (LPARAM)(LPCTSTR) wUnicode );
195                         free( wUnicode );
196                     }
197                 }
198             }
199
200             /* Manage Playing status */
201             var_Get( p_input, "state", &val );
202             if( i_old_playing_status != val.i_int )
203             {
204                 if( val.i_int == PAUSE_S )
205                 {
206                     p_main_interface->TogglePlayButton( PAUSE_S );
207                 }
208                 else
209                 {
210                     p_main_interface->TogglePlayButton( PLAYING_S );
211                 }
212                 i_old_playing_status = val.i_int;
213             }
214
215             /* Manage Speed status */
216             var_Get( p_input, "rate", &val );
217             if( i_old_rate != val.i_int )
218             {
219                 wUnicode = new WCHAR[10];
220                 swprintf( wUnicode + 2, TEXT("x%.2f"), 1000.0 / val.i_int );
221                 wUnicode[0] = L'\t';
222                 wUnicode[1] = L'\t';
223
224                 SendMessage( p_main_interface->hwndSB, SB_SETTEXT, 
225                              (WPARAM) 1, (LPARAM)(LPCTSTR) wUnicode);
226
227                 free(wUnicode); 
228
229                 i_old_rate = val.i_int;
230             }
231         }
232     }
233     else if( p_intf->p_sys->b_playing && !p_intf->b_die )
234     {
235         p_intf->p_sys->b_playing = 0;
236         p_main_interface->TogglePlayButton( PAUSE_S );
237         i_old_playing_status = PAUSE_S;
238     }
239
240     if( p_intf->b_die )
241     {
242         vlc_mutex_unlock( &p_intf->change_lock );
243
244         /* Prepare to die, young Skywalker */
245 /*        p_main_interface->Close(TRUE);*/
246         return;
247     }
248
249     vlc_mutex_unlock( &p_intf->change_lock );
250 }
251
252 /*****************************************************************************
253  * PopupMenuCB: callback triggered by the intf-popupmenu playlist variable.
254  *  We don't show the menu directly here because we don't want the
255  *  caller to block for a too long time.
256  *****************************************************************************/
257 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
258                         vlc_value_t old_val, vlc_value_t new_val, void *param )
259 {
260     intf_thread_t *p_intf = (intf_thread_t *)param;
261
262     if( p_intf->p_sys->pf_show_dialog )
263     {
264         p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU,
265                                        new_val.b_bool, 0 );
266     }
267
268     return VLC_SUCCESS;
269 }