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() */
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 * );
43 /*****************************************************************************
45 *****************************************************************************/
46 Timer::Timer( intf_thread_t *_p_intf, HWND hwnd, Interface *_p_main_interface)
49 p_main_interface = _p_main_interface;
50 i_old_playing_status = PAUSE_S;
51 i_old_rate = INPUT_RATE_DEFAULT;
53 /* Register callback for the intf-popupmenu variable */
54 playlist_t *p_playlist =
55 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
57 if( p_playlist != NULL )
59 var_AddCallback( p_playlist, "intf-popupmenu", PopupMenuCB, p_intf );
60 vlc_object_release( p_playlist );
63 SetTimer( hwnd, 1, 200 /*milliseconds*/, NULL );
68 /* Unregister callback */
69 playlist_t *p_playlist =
70 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
72 if( p_playlist != NULL )
74 var_DelCallback( p_playlist, "intf-popupmenu", PopupMenuCB, p_intf );
75 vlc_object_release( p_playlist );
79 /*****************************************************************************
81 *****************************************************************************/
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 )
94 vlc_mutex_lock( &p_intf->change_lock );
96 /* Update the input */
97 if( p_intf->p_sys->p_input == NULL )
99 p_intf->p_sys->p_input =
100 (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
104 if( p_intf->p_sys->p_input )
106 ShowWindow( p_main_interface->hwndSlider, SW_SHOW );
107 ShowWindow( p_main_interface->hwndLabel, SW_SHOW );
108 ShowWindow( p_main_interface->hwndVol, SW_SHOW );
110 // only for local file, check if works well with net url
111 shortname = strrchr( p_intf->p_sys->p_input->input.p_item->psz_name, '\\' );
113 shortname = p_intf->p_sys->p_input->input.p_item->psz_name;
116 SendMessage( p_main_interface->hwndSB, SB_SETTEXT,
117 (WPARAM) 0, (LPARAM)_FROMMB(shortname) );
119 p_main_interface->TogglePlayButton( PLAYING_S );
120 i_old_playing_status = PLAYING_S;
123 else if( p_intf->p_sys->p_input->b_dead )
126 ShowWindow( p_main_interface->hwndSlider, SW_HIDE);
127 ShowWindow( p_main_interface->hwndLabel, SW_HIDE);
128 ShowWindow( p_main_interface->hwndVol, SW_HIDE);
130 p_main_interface->TogglePlayButton( PAUSE_S );
131 i_old_playing_status = PAUSE_S;
133 SendMessage( p_main_interface->hwndSB, SB_SETTEXT,
134 (WPARAM) 0, (LPARAM)(LPCTSTR) TEXT(""));
136 vlc_object_release( p_intf->p_sys->p_input );
137 p_intf->p_sys->p_input = NULL;
140 if( p_intf->p_sys->p_input )
142 input_thread_t *p_input = p_intf->p_sys->p_input;
144 if( !p_input->b_die )
146 /* New input or stream map change */
147 p_intf->p_sys->b_playing = 1;
149 /* Manage the slider */
150 if( /*p_input->stream.b_seekable &&*/ p_intf->p_sys->b_playing )
152 /* Update the slider if the user isn't dragging it. */
153 if( p_intf->p_sys->b_slider_free )
156 char psz_time[ MSTRTIME_MAX_SIZE ];
160 /* Update the value */
161 var_Get( p_input, "position", &pos );
162 if( pos.f_float >= 0.0 )
164 p_intf->p_sys->i_slider_pos =
165 (int)(SLIDER_MAX_POS * pos.f_float);
167 SendMessage( p_main_interface->hwndSlider, TBM_SETPOS,
168 1, p_intf->p_sys->i_slider_pos );
170 var_Get( p_intf->p_sys->p_input, "time", &time );
171 i_seconds = time.i_time / 1000000;
172 secstotimestr ( psz_time, i_seconds );
174 SendMessage( p_main_interface->hwndLabel, WM_SETTEXT,
175 (WPARAM)1, (LPARAM)_FROMMB(psz_time) );
180 /* Take care of the volume, etc... */
181 p_main_interface->Update();
183 /* Manage Playing status */
184 var_Get( p_input, "state", &val );
185 if( i_old_playing_status != val.i_int )
187 if( val.i_int == PAUSE_S )
189 p_main_interface->TogglePlayButton( PAUSE_S );
193 p_main_interface->TogglePlayButton( PLAYING_S );
195 i_old_playing_status = val.i_int;
198 /* Manage Speed status */
199 var_Get( p_input, "rate", &val );
200 if( i_old_rate != val.i_int )
203 _stprintf( psz_text + 2, _T("x%.2f"), 1000.0 / val.i_int );
204 psz_text[0] = psz_text[1] = _T('\t');
206 SendMessage( p_main_interface->hwndSB, SB_SETTEXT,
207 (WPARAM) 1, (LPARAM)(LPCTSTR) psz_text );
209 i_old_rate = val.i_int;
213 else if( p_intf->p_sys->b_playing && !p_intf->b_die )
215 p_intf->p_sys->b_playing = 0;
216 p_main_interface->TogglePlayButton( PAUSE_S );
217 i_old_playing_status = PAUSE_S;
222 vlc_mutex_unlock( &p_intf->change_lock );
224 /* Prepare to die, young Skywalker */
225 /* p_main_interface->Close(TRUE);*/
229 vlc_mutex_unlock( &p_intf->change_lock );
232 /*****************************************************************************
233 * PopupMenuCB: callback triggered by the intf-popupmenu playlist variable.
234 * We don't show the menu directly here because we don't want the
235 * caller to block for a too long time.
236 *****************************************************************************/
237 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
238 vlc_value_t old_val, vlc_value_t new_val, void *param )
240 intf_thread_t *p_intf = (intf_thread_t *)param;
242 if( p_intf->p_sys->pf_show_dialog )
244 p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU,