1 /*****************************************************************************
2 * timer.cpp : wxWindows plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000-2003 VideoLAN
7 * Authors: Gildas Bazin <gbazin@videolan.org>
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.
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.
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 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
27 #include <stdlib.h> /* malloc(), free() */
28 #include <errno.h> /* ENOMEM */
29 #include <string.h> /* strerror() */
38 #include "wxwindows.h"
41 //void DisplayStreamDate( wxControl *, intf_thread_t *, int );
43 /* Callback prototypes */
44 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
45 vlc_value_t old_val, vlc_value_t new_val, void *param );
46 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
47 vlc_value_t old_val, vlc_value_t new_val, void *param );
49 /*****************************************************************************
51 *****************************************************************************/
52 Timer::Timer( intf_thread_t *_p_intf, Interface *_p_main_interface )
55 p_main_interface = _p_main_interface;
57 i_old_playing_status = PAUSE_S;
58 i_old_rate = INPUT_RATE_DEFAULT;
60 /* Register callback for the intf-popupmenu variable */
61 playlist_t *p_playlist =
62 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
64 if( p_playlist != NULL )
66 var_AddCallback( p_playlist, "intf-popupmenu", PopupMenuCB, p_intf );
67 var_AddCallback( p_playlist, "intf-show", IntfShowCB, p_intf );
68 vlc_object_release( p_playlist );
71 Start( 100 /*milliseconds*/, wxTIMER_CONTINUOUS );
76 /* Unregister callback */
77 playlist_t *p_playlist =
78 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
80 if( p_playlist != NULL )
82 var_DelCallback( p_playlist, "intf-popupmenu", PopupMenuCB, p_intf );
83 var_DelCallback( p_playlist, "intf-show", IntfShowCB, p_intf );
84 vlc_object_release( p_playlist );
87 vlc_mutex_lock( &p_intf->change_lock );
88 if( p_intf->p_sys->p_input ) vlc_object_release( p_intf->p_sys->p_input );
89 p_intf->p_sys->p_input = NULL;
90 vlc_mutex_unlock( &p_intf->change_lock );
93 /*****************************************************************************
95 *****************************************************************************/
97 /*****************************************************************************
98 * Manage: manage main thread messages
99 *****************************************************************************
100 * In this function, called approx. 10 times a second, we check what the
101 * main program wanted to tell us.
102 *****************************************************************************/
105 #if defined( __WXMSW__ ) /* Work-around a bug with accelerators */
108 p_main_interface->Init();
113 vlc_mutex_lock( &p_intf->change_lock );
115 /* Update the input */
116 if( p_intf->p_sys->p_input == NULL )
118 playlist_t *p_playlist =
119 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
121 if( p_playlist != NULL )
123 vlc_mutex_lock( &p_playlist->object_lock );
124 p_intf->p_sys->p_input = p_playlist->p_input;
125 if( p_intf->p_sys->p_input )
126 vlc_object_yield( p_intf->p_sys->p_input );
127 vlc_mutex_unlock( &p_playlist->object_lock );
128 vlc_object_release( p_playlist );
131 /* Refresh interface */
132 if( p_intf->p_sys->p_input )
134 p_main_interface->slider->SetValue( 0 );
135 b_old_seekable = VLC_FALSE;
136 b_disc_shown = VLC_FALSE;
138 char *psz_now_playing = vlc_input_item_GetInfo(
139 p_intf->p_sys->p_input->input.p_item,
140 _("Meta-information"), _( "Now Playing" ) );
141 if( psz_now_playing && *psz_now_playing )
143 p_main_interface->statusbar->SetStatusText(
144 wxU(psz_now_playing) + wxT( " - " ) +
145 wxU(p_intf->p_sys->p_input->input.p_item->psz_name), 2 );
149 p_main_interface->statusbar->SetStatusText(
150 wxU(p_intf->p_sys->p_input->input.p_item->psz_name), 2 );
152 free( psz_now_playing );
154 p_main_interface->TogglePlayButton( PLAYING_S );
155 #ifdef wxHAS_TASK_BAR_ICON
156 if( p_main_interface->p_systray )
158 p_main_interface->p_systray->UpdateTooltip( wxU(p_intf->p_sys->p_input->input.p_item->psz_name) + wxString(wxT(" - ")) + wxU(_("Playing")));
161 i_old_playing_status = PLAYING_S;
164 else if( p_intf->p_sys->p_input->b_dead )
166 /* Hide slider and Disc Buttons */
167 p_main_interface->disc_frame->Hide();
168 p_main_interface->slider_sizer->Hide(
169 p_main_interface->disc_frame );
170 p_main_interface->slider_sizer->Layout();
171 p_main_interface->slider_sizer->Fit( p_main_interface->slider_frame );
173 p_main_interface->slider_frame->Hide();
174 p_main_interface->frame_sizer->Hide(
175 p_main_interface->slider_frame );
176 p_main_interface->frame_sizer->Layout();
177 p_main_interface->frame_sizer->Fit( p_main_interface );
179 p_main_interface->TogglePlayButton( PAUSE_S );
180 i_old_playing_status = PAUSE_S;
182 p_main_interface->statusbar->SetStatusText( wxT(""), 0 );
183 p_main_interface->statusbar->SetStatusText( wxT(""), 2 );
185 #ifdef wxHAS_TASK_BAR_ICON
186 if( p_main_interface->p_systray )
188 p_main_interface->p_systray->UpdateTooltip( wxString(wxT("VLC media player - ")) + wxU(_("Stopped")) );
191 vlc_object_release( p_intf->p_sys->p_input );
192 p_intf->p_sys->p_input = NULL;
195 if( p_intf->p_sys->p_input )
197 input_thread_t *p_input = p_intf->p_sys->p_input;
200 if( !p_input->b_die )
204 /* New input or stream map change */
205 p_intf->p_sys->b_playing = 1;
207 /* Update the item name */
208 char *psz_now_playing = vlc_input_item_GetInfo(
209 p_intf->p_sys->p_input->input.p_item,
210 _("Meta-information"), _( "Now Playing" ) );
211 if( psz_now_playing && *psz_now_playing )
213 p_main_interface->statusbar->SetStatusText(
214 wxU(psz_now_playing) + wxT( " - " ) +
215 wxU(p_intf->p_sys->p_input->input.p_item->psz_name), 2 );
219 p_main_interface->statusbar->SetStatusText(
220 wxU(p_intf->p_sys->p_input->input.p_item->psz_name), 2 );
222 free( psz_now_playing );
224 /* Manage the slider */
226 /* Change the name of b_old_seekable into b_show_bar or something like that */
227 var_Get( p_input, "position", &pos );
229 var_Change( p_input, "title", VLC_VAR_CHOICESCOUNT, &val, NULL );
230 if( val.i_int > 0 && !b_disc_shown )
232 b_disc_shown = VLC_TRUE;
235 #define HELP_MENU N_("Menu")
236 #define HELP_PCH N_("Previous chapter")
237 #define HELP_NCH N_("Next chapter")
238 #define HELP_PTR N_("Previous track")
239 #define HELP_NTR N_("Next track")
241 var_Change( p_input, "chapter", VLC_VAR_CHOICESCOUNT, &val,
246 p_main_interface->disc_menu_button->Show();
247 p_main_interface->disc_sizer->Show(
248 p_main_interface->disc_menu_button );
249 p_main_interface->disc_sizer->Layout();
250 p_main_interface->disc_sizer->Fit(
251 p_main_interface->disc_frame );
253 p_main_interface->disc_menu_button->SetToolTip(
254 wxU(_( HELP_MENU ) ) );
255 p_main_interface->disc_prev_button->SetToolTip(
256 wxU(_( HELP_PCH ) ) );
257 p_main_interface->disc_next_button->SetToolTip(
258 wxU(_( HELP_NCH ) ) );
262 p_main_interface->disc_menu_button->Hide();
263 p_main_interface->disc_sizer->Hide(
264 p_main_interface->disc_menu_button );
266 p_main_interface->disc_prev_button->SetToolTip(
267 wxU(_( HELP_PTR ) ) );
268 p_main_interface->disc_next_button->SetToolTip(
269 wxU(_( HELP_NTR ) ) );
272 p_main_interface->disc_frame->Show();
273 p_main_interface->slider_sizer->Show(
274 p_main_interface->disc_frame );
277 if( ! b_old_seekable )
279 if( pos.f_float > 0.0 )
281 /* Done like this, as it's the only way to know if the */
282 /* slider has to be displayed */
283 b_old_seekable = VLC_TRUE;
284 p_main_interface->slider_frame->Show();
285 p_main_interface->frame_sizer->Show(
286 p_main_interface->slider_frame );
287 p_main_interface->frame_sizer->Layout();
288 p_main_interface->frame_sizer->Fit( p_main_interface );
292 if( p_intf->p_sys->b_playing && b_old_seekable )
294 /* Update the slider if the user isn't dragging it. */
295 if( p_intf->p_sys->b_slider_free )
297 char psz_time[ MSTRTIME_MAX_SIZE ];
298 char psz_total[ MSTRTIME_MAX_SIZE ];
302 /* Update the value */
303 if( pos.f_float >= 0.0 )
305 p_intf->p_sys->i_slider_pos =
306 (int)(SLIDER_MAX_POS * pos.f_float);
308 p_main_interface->slider->SetValue(
309 p_intf->p_sys->i_slider_pos );
311 var_Get( p_intf->p_sys->p_input, "time", &time );
312 i_seconds = time.i_time / 1000000;
313 secstotimestr ( psz_time, i_seconds );
315 var_Get( p_intf->p_sys->p_input, "length", &time );
316 i_seconds = time.i_time / 1000000;
317 secstotimestr ( psz_total, i_seconds );
319 p_main_interface->statusbar->SetStatusText(
320 wxU(psz_time) + wxString(wxT(" / ")) +
326 vlc_mutex_lock( &p_input->stream.stream_lock );
327 if( p_intf->p_sys->p_input->stream.b_seekable && !b_old_seekable )
329 /* Done like this because b_seekable is set slightly after
330 * the new input object is available. */
331 b_old_seekable = VLC_TRUE;
332 p_main_interface->slider_frame->Show();
333 p_main_interface->frame_sizer->Show(
334 p_main_interface->slider_frame );
335 p_main_interface->frame_sizer->Layout();
336 p_main_interface->frame_sizer->Fit( p_main_interface );
338 if( p_input->stream.b_seekable && p_intf->p_sys->b_playing )
340 /* Update the slider if the user isn't dragging it. */
341 if( p_intf->p_sys->b_slider_free )
344 char psz_time[ MSTRTIME_MAX_SIZE ];
345 char psz_total[ MSTRTIME_MAX_SIZE ];
349 /* Update the value */
350 var_Get( p_input, "position", &pos );
351 if( pos.f_float >= 0.0 )
353 p_intf->p_sys->i_slider_pos =
354 (int)(SLIDER_MAX_POS * pos.f_float);
356 p_main_interface->slider->SetValue(
357 p_intf->p_sys->i_slider_pos );
359 var_Get( p_intf->p_sys->p_input, "time", &time );
360 i_seconds = time.i_time / 1000000;
361 secstotimestr ( psz_time, i_seconds );
363 var_Get( p_intf->p_sys->p_input, "length", &time );
364 i_seconds = time.i_time / 1000000;
365 secstotimestr ( psz_total, i_seconds );
367 p_main_interface->statusbar->SetStatusText(
368 wxU(psz_time) + wxString(wxT(" / ")) +
373 vlc_mutex_unlock( &p_input->stream.stream_lock );
375 /* Take care of the volume, etc... */
376 p_main_interface->Update();
378 /* Manage Playing status */
379 var_Get( p_input, "state", &val );
380 if( i_old_playing_status != val.i_int )
382 if( val.i_int == PAUSE_S )
384 p_main_interface->TogglePlayButton( PAUSE_S );
388 p_main_interface->TogglePlayButton( PLAYING_S );
390 #ifdef wxHAS_TASK_BAR_ICON
391 if( p_main_interface->p_systray )
393 if( val.i_int == PAUSE_S )
395 p_main_interface->p_systray->UpdateTooltip( wxU(p_intf->p_sys->p_input->input.p_item->psz_name) + wxString(wxT(" - ")) + wxU(_("Paused")));
399 p_main_interface->p_systray->UpdateTooltip( wxU(p_intf->p_sys->p_input->input.p_item->psz_name) + wxString(wxT(" - ")) + wxU(_("Playing")));
403 i_old_playing_status = val.i_int;
406 /* Manage Speed status */
407 var_Get( p_input, "rate", &val );
408 if( i_old_rate != val.i_int )
410 p_main_interface->statusbar->SetStatusText(
411 wxString::Format(wxT("x%.2f"),
412 (float)INPUT_RATE_DEFAULT / val.i_int ), 1 );
413 i_old_rate = val.i_int;
418 else if( p_intf->p_sys->b_playing && !p_intf->b_die )
420 p_intf->p_sys->b_playing = 0;
421 p_main_interface->TogglePlayButton( PAUSE_S );
422 i_old_playing_status = PAUSE_S;
425 /* Show the interface, if requested */
426 if( p_intf->p_sys->b_intf_show )
428 p_main_interface->Raise();
429 p_intf->p_sys->b_intf_show = VLC_FALSE;
434 vlc_mutex_unlock( &p_intf->change_lock );
436 /* Prepare to die, young Skywalker */
437 p_main_interface->Close(TRUE);
441 vlc_mutex_unlock( &p_intf->change_lock );
444 /*****************************************************************************
445 * PopupMenuCB: callback triggered by the intf-popupmenu playlist variable.
446 * We don't show the menu directly here because we don't want the
447 * caller to block for a too long time.
448 *****************************************************************************/
449 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
450 vlc_value_t old_val, vlc_value_t new_val, void *param )
452 intf_thread_t *p_intf = (intf_thread_t *)param;
454 if( p_intf->p_sys->pf_show_dialog )
456 p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU,
463 /*****************************************************************************
464 * IntfShowCB: callback triggered by the intf-show playlist variable.
465 *****************************************************************************/
466 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
467 vlc_value_t old_val, vlc_value_t new_val, void *param )
469 intf_thread_t *p_intf = (intf_thread_t *)param;
470 p_intf->p_sys->b_intf_show = VLC_TRUE;