1 /*****************************************************************************
2 * timer.cpp : WinCE gui plugin for VLC
3 *****************************************************************************
4 * Copyright (C) 2000-2003 VideoLAN
7 * Authors: Marodon Cedric <cedric_marodon@yahoo.fr>
8 * Gildas Bazin <gbazin@videolan.org>
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.
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.
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 *****************************************************************************/
25 /*****************************************************************************
27 *****************************************************************************/
28 #include <stdlib.h> /* malloc(), free() */
29 #include <string.h> /* strerror() */
44 /* Callback prototype */
45 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
46 vlc_value_t old_val, vlc_value_t new_val, void *param );
48 /*****************************************************************************
50 *****************************************************************************/
51 Timer::Timer( intf_thread_t *_p_intf, HWND hwnd, Interface *_p_main_interface)//, Interface *_p_main_interface )
54 p_main_interface = _p_main_interface;
55 i_old_playing_status = PAUSE_S;
56 i_old_rate = INPUT_RATE_DEFAULT;
58 /* Register callback for the intf-popupmenu variable */
59 playlist_t *p_playlist =
60 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
62 if( p_playlist != NULL )
64 var_AddCallback( p_playlist, "intf-popupmenu", PopupMenuCB, p_intf );
65 vlc_object_release( p_playlist );
68 SetTimer( hwnd, 1, 200 /*milliseconds*/, NULL );
73 /* Unregister callback */
74 playlist_t *p_playlist =
75 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
77 if( p_playlist != NULL )
79 var_DelCallback( p_playlist, "intf-popupmenu", PopupMenuCB, p_intf );
80 vlc_object_release( p_playlist );
84 /*****************************************************************************
86 *****************************************************************************/
88 /*****************************************************************************
89 * Manage: manage main thread messages
90 *****************************************************************************
91 * In this function, called approx. 10 times a second, we check what the
92 * main program wanted to tell us.
93 *****************************************************************************/
94 void Timer::Notify( void )
101 vlc_mutex_lock( &p_intf->change_lock );
103 /* Update the input */
104 if( p_intf->p_sys->p_input == NULL )
106 p_intf->p_sys->p_input =
107 (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
111 if( p_intf->p_sys->p_input )
113 ShowWindow( p_main_interface->hwndSlider, SW_SHOW);
114 ShowWindow( p_main_interface->hwndLabel, SW_SHOW);
115 ShowWindow( p_main_interface->hwndVol, SW_SHOW);
117 // only for local file, check if works well with net url
118 shortname = strrchr( p_intf->p_sys->p_input->input.p_item->psz_name, '\\' );
120 shortname = p_intf->p_sys->p_input->input.p_item->psz_name;
124 size = MultiByteToWideChar (CP_ACP, 0, shortname, -1, NULL, 0);
125 wUnicode = new WCHAR[size+1];
126 MultiByteToWideChar (CP_ACP, 0, shortname, -1, wUnicode + 1, size) ;
129 SendMessage( p_main_interface->hwndSB, SB_SETTEXT,
130 (WPARAM) 0, (LPARAM)(LPCTSTR) wUnicode);
133 p_main_interface->TogglePlayButton( PLAYING_S );
134 i_old_playing_status = PLAYING_S;
136 /* Take care of the volume */
137 audio_volume_t i_volume;
138 aout_VolumeGet( p_intf, &i_volume );
139 SendMessage( p_main_interface->hwndVol, TBM_SETPOS, 1,
140 200 - (i_volume * 200 * 2 / AOUT_VOLUME_MAX ) );
143 else if( p_intf->p_sys->p_input->b_dead )
146 ShowWindow( p_main_interface->hwndSlider, SW_HIDE);
147 ShowWindow( p_main_interface->hwndLabel, SW_HIDE);
148 ShowWindow( p_main_interface->hwndVol, SW_HIDE);
150 p_main_interface->TogglePlayButton( PAUSE_S );
151 i_old_playing_status = PAUSE_S;
153 SendMessage( p_main_interface->hwndSB, SB_SETTEXT,
154 (WPARAM) 0, (LPARAM)(LPCTSTR) TEXT(""));
156 vlc_object_release( p_intf->p_sys->p_input );
157 p_intf->p_sys->p_input = NULL;
160 if( p_intf->p_sys->p_input )
162 input_thread_t *p_input = p_intf->p_sys->p_input;
164 if( !p_input->b_die )
166 /* New input or stream map change */
167 p_intf->p_sys->b_playing = 1;
169 /* Manage the slider */
170 if( /*p_input->stream.b_seekable &&*/ p_intf->p_sys->b_playing )
172 /* Update the slider if the user isn't dragging it. */
173 if( p_intf->p_sys->b_slider_free )
176 char psz_time[ MSTRTIME_MAX_SIZE ];
180 /* Update the value */
181 var_Get( p_input, "position", &pos );
182 if( pos.f_float >= 0.0 )
184 p_intf->p_sys->i_slider_pos =
185 (int)(SLIDER_MAX_POS * pos.f_float);
187 SendMessage( p_main_interface->hwndSlider,TBM_SETPOS,
188 1, p_intf->p_sys->i_slider_pos );
190 var_Get( p_intf->p_sys->p_input, "time", &time );
191 i_seconds = time.i_time / 1000000;
193 secstotimestr ( psz_time, i_seconds );
195 size = MultiByteToWideChar (CP_ACP, 0, psz_time, -1, NULL, 0);
196 wUnicode = new WCHAR[size];
197 MultiByteToWideChar (CP_ACP, 0, psz_time, -1, wUnicode, size) ;
198 SendMessage( p_main_interface->hwndLabel, WM_SETTEXT,
199 (WPARAM) 1, (LPARAM)(LPCTSTR) wUnicode );
205 /* Manage Playing status */
206 var_Get( p_input, "state", &val );
207 if( i_old_playing_status != val.i_int )
209 if( val.i_int == PAUSE_S )
211 p_main_interface->TogglePlayButton( PAUSE_S );
215 p_main_interface->TogglePlayButton( PLAYING_S );
217 i_old_playing_status = val.i_int;
220 /* Manage Speed status */
221 var_Get( p_input, "rate", &val );
222 if( i_old_rate != val.i_int )
224 wUnicode = new WCHAR[10];
225 swprintf( wUnicode + 2, TEXT("x%.2f"), 1000.0 / val.i_int );
229 SendMessage( p_main_interface->hwndSB, SB_SETTEXT,
230 (WPARAM) 1, (LPARAM)(LPCTSTR) wUnicode);
234 i_old_rate = val.i_int;
238 else if( p_intf->p_sys->b_playing && !p_intf->b_die )
240 p_intf->p_sys->b_playing = 0;
241 p_main_interface->TogglePlayButton( PAUSE_S );
242 i_old_playing_status = PAUSE_S;
247 vlc_mutex_unlock( &p_intf->change_lock );
249 /* Prepare to die, young Skywalker */
250 /* p_main_interface->Close(TRUE);*/
254 vlc_mutex_unlock( &p_intf->change_lock );
257 /*****************************************************************************
258 * PopupMenuCB: callback triggered by the intf-popupmenu playlist variable.
259 * We don't show the menu directly here because we don't want the
260 * caller to block for a too long time.
261 *****************************************************************************/
262 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
263 vlc_value_t old_val, vlc_value_t new_val, void *param )
265 intf_thread_t *p_intf = (intf_thread_t *)param;
267 if( p_intf->p_sys->pf_show_dialog )
269 p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU,