X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fgui%2Fwxwindows%2Ftimer.cpp;h=4d3c5a2d6a242115fe0bda8ce43526d140a675bb;hb=85d667d783d0bc757665f504acdbaf01a969b751;hp=7321913abcedbcd72545c77be4ae1eb1335e251b;hpb=30336bba3f772a1b20a1c5a0663635b1bffc6c68;p=vlc diff --git a/modules/gui/wxwindows/timer.cpp b/modules/gui/wxwindows/timer.cpp index 7321913abc..4d3c5a2d6a 100644 --- a/modules/gui/wxwindows/timer.cpp +++ b/modules/gui/wxwindows/timer.cpp @@ -1,10 +1,10 @@ /***************************************************************************** * timer.cpp : wxWindows plugin for vlc ***************************************************************************** - * Copyright (C) 2000-2001 VideoLAN - * $Id: timer.cpp,v 1.14 2003/05/04 22:42:16 gbazin Exp $ + * Copyright (C) 2000-2005 VideoLAN + * $Id$ * - * Authors: Gildas Bazin + * Authors: Gildas Bazin * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -30,24 +30,21 @@ #include #include +#include +#include -#ifdef WIN32 /* mingw32 hack */ -#undef Yield -#undef CreateDialog -#endif - -/* Let vlc take care of the i18n stuff */ -#define WXINTL_NO_GETTEXT_MACRO +#include "vlc_meta.h" -#include -#include +#include "wxwindows.h" #include -#include - -#include "wxwindows.h" +//void DisplayStreamDate( wxControl *, intf_thread_t *, int ); -void DisplayStreamDate( wxControl *, intf_thread_t *, int ); +/* Callback prototypes */ +static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable, + vlc_value_t old_val, vlc_value_t new_val, void *param ); +static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable, + vlc_value_t old_val, vlc_value_t new_val, void *param ); /***************************************************************************** * Constructor. @@ -56,39 +53,46 @@ Timer::Timer( intf_thread_t *_p_intf, Interface *_p_main_interface ) { p_intf = _p_intf; p_main_interface = _p_main_interface; + b_init = 0; i_old_playing_status = PAUSE_S; + i_old_rate = INPUT_RATE_DEFAULT; + + /* Register callback for the intf-popupmenu variable */ + playlist_t *p_playlist = + (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, + FIND_ANYWHERE ); + if( p_playlist != NULL ) + { + var_AddCallback( p_playlist, "intf-popupmenu", PopupMenuCB, p_intf ); + var_AddCallback( p_playlist, "intf-show", IntfShowCB, p_intf ); + vlc_object_release( p_playlist ); + } Start( 100 /*milliseconds*/, wxTIMER_CONTINUOUS ); } Timer::~Timer() { -} + /* Unregister callback */ + playlist_t *p_playlist = + (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, + FIND_ANYWHERE ); + if( p_playlist != NULL ) + { + var_DelCallback( p_playlist, "intf-popupmenu", PopupMenuCB, p_intf ); + var_DelCallback( p_playlist, "intf-show", IntfShowCB, p_intf ); + vlc_object_release( p_playlist ); + } -/***************************************************************************** - * Private methods. - *****************************************************************************/ -/***************************************************************************** - * wxModeManage: actualise the aspect of the interface whenever the input - * changes. - ***************************************************************************** - * The lock has to be taken before you call the function. - *****************************************************************************/ -static int wxModeManage( intf_thread_t * p_intf ) -{ - return 0; + vlc_mutex_lock( &p_intf->change_lock ); + if( p_intf->p_sys->p_input ) vlc_object_release( p_intf->p_sys->p_input ); + p_intf->p_sys->p_input = NULL; + vlc_mutex_unlock( &p_intf->change_lock ); } /***************************************************************************** - * wxSetupMenus: function that generates title/chapter/audio/subpic - * menus with help from preceding functions - ***************************************************************************** - * Function called with the lock on stream + * Private methods. *****************************************************************************/ -static int wxSetupMenus( intf_thread_t * p_intf ) -{ - return 0; -} /***************************************************************************** * Manage: manage main thread messages @@ -98,138 +102,222 @@ static int wxSetupMenus( intf_thread_t * p_intf ) *****************************************************************************/ void Timer::Notify() { - vlc_bool_t b_pace_control; - - vlc_mutex_lock( &p_intf->change_lock ); - - /* If the "display popup" flag has changed */ - if( p_intf->b_menu_change ) +#if defined( __WXMSW__ ) /* Work-around a bug with accelerators */ + if( !b_init ) { - PopupMenu( p_intf, p_main_interface ); - p_intf->b_menu_change = 0; + p_main_interface->Init(); + b_init = VLC_TRUE; } +#endif - /* Update the log window */ - p_intf->p_sys->p_messages_window->UpdateLog(); - - /* Update the playlist */ - p_intf->p_sys->p_playlist_window->Manage(); + vlc_mutex_lock( &p_intf->change_lock ); - /* Update the fileinfo windows */ - p_intf->p_sys->p_fileinfo_window->UpdateFileInfo(); - /* Update the input */ if( p_intf->p_sys->p_input == NULL ) { - p_intf->p_sys->p_input = (input_thread_t *)vlc_object_find( p_intf, - VLC_OBJECT_INPUT, - FIND_ANYWHERE ); + playlist_t *p_playlist = + (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, + FIND_ANYWHERE ); + if( p_playlist != NULL ) + { + LockPlaylist( p_intf->p_sys, p_playlist ); + p_intf->p_sys->p_input = p_playlist->p_input; + if( p_intf->p_sys->p_input ) + vlc_object_yield( p_intf->p_sys->p_input ); + UnlockPlaylist( p_intf->p_sys, p_playlist ); + vlc_object_release( p_playlist ); + } - /* Show slider */ + /* Refresh interface */ if( p_intf->p_sys->p_input ) { - //if( p_intf->p_sys->p_input->stream.b_seekable ) + p_main_interface->slider->SetValue( 0 ); + + char *psz_now_playing = vlc_input_item_GetInfo( + p_intf->p_sys->p_input->input.p_item, + _("Meta-information"), _( "Now Playing" ) ); + if( psz_now_playing && *psz_now_playing ) { - p_main_interface->slider_frame->Show(); - p_main_interface->frame_sizer->Show( - p_main_interface->slider_frame ); - p_main_interface->frame_sizer->Layout(); - p_main_interface->frame_sizer->Fit( p_main_interface ); + p_main_interface->statusbar->SetStatusText( + wxString(wxU(psz_now_playing)) + wxT( " - " ) + + wxU(p_intf->p_sys->p_input->input.p_item->psz_name), 2 ); } - - p_main_interface->statusbar->SetStatusText( - p_intf->p_sys->p_input->psz_source, 1 ); + else + { + p_main_interface->statusbar->SetStatusText( + wxU(p_intf->p_sys->p_input->input.p_item->psz_name), 2 ); + } + free( psz_now_playing ); p_main_interface->TogglePlayButton( PLAYING_S ); +#ifdef wxHAS_TASK_BAR_ICON + if( p_main_interface->p_systray ) + { + p_main_interface->p_systray->UpdateTooltip( wxU(p_intf->p_sys->p_input->input.p_item->psz_name) + wxString(wxT(" - ")) + wxU(_("Playing"))); + } +#endif i_old_playing_status = PLAYING_S; } - - /* control buttons for free pace streams */ - b_pace_control = p_intf->p_sys->p_input->stream.b_pace_control; - } else if( p_intf->p_sys->p_input->b_dead ) { - /* Hide slider */ - //if( p_intf->p_sys->p_input->stream.b_seekable ) - { - p_main_interface->slider_frame->Hide(); - p_main_interface->frame_sizer->Hide( - p_main_interface->slider_frame ); - p_main_interface->frame_sizer->Layout(); - p_main_interface->frame_sizer->Fit( p_main_interface ); - - p_main_interface->TogglePlayButton( PAUSE_S ); - i_old_playing_status = PAUSE_S; - } + //controls auto-hide after a timer + p_main_interface->m_controls_timer.Start(200, wxTIMER_ONE_SHOT); - p_main_interface->statusbar->SetStatusText( "", 1 ); + p_main_interface->TogglePlayButton( PAUSE_S ); + i_old_playing_status = PAUSE_S; + + p_main_interface->statusbar->SetStatusText( wxT(""), 0 ); + p_main_interface->statusbar->SetStatusText( wxT(""), 2 ); +#ifdef wxHAS_TASK_BAR_ICON + if( p_main_interface->p_systray ) + { + p_main_interface->p_systray->UpdateTooltip( wxString(wxT("VLC media player - ")) + wxU(_("Stopped")) ); + } +#endif vlc_object_release( p_intf->p_sys->p_input ); p_intf->p_sys->p_input = NULL; } - - if( p_intf->p_sys->p_input ) { input_thread_t *p_input = p_intf->p_sys->p_input; - - vlc_mutex_lock( &p_input->stream.stream_lock ); + vlc_value_t val; if( !p_input->b_die ) { + vlc_value_t pos; + + //prevent the controls from auto-hiding + p_main_interface->m_controls_timer.Stop(); + /* New input or stream map change */ p_intf->p_sys->b_playing = 1; -#if 0 - if( p_input->stream.b_changed ) - { - wxModeManage( p_intf ); - wxSetupMenus( p_intf ); - p_intf->p_sys->b_playing = 1; - p_main_interface->TogglePlayButton( PLAYING_S ); - i_old_playing_status = PLAYING_S; + /* Update the item name */ + char *psz_now_playing = vlc_input_item_GetInfo( + p_intf->p_sys->p_input->input.p_item, + _("Meta-information"), _( "Now Playing" ) ); + if( psz_now_playing && *psz_now_playing ) + { + p_main_interface->statusbar->SetStatusText( + wxString(wxU(psz_now_playing)) + wxT( " - " ) + + wxU(p_intf->p_sys->p_input->input.p_item->psz_name), 2 ); } -#endif + else + { + p_main_interface->statusbar->SetStatusText( + wxU(p_intf->p_sys->p_input->input.p_item->psz_name), 2 ); + } + free( psz_now_playing ); /* Manage the slider */ - if( p_input->stream.b_seekable && p_intf->p_sys->b_playing ) + var_Get( p_input, "position", &pos ); + + var_Change( p_input, "title", VLC_VAR_CHOICESCOUNT, &val, NULL ); + if( val.i_int > 0 && !p_main_interface->disc_frame->IsShown() ) + { + vlc_value_t val; + + #define HELP_MENU N_("Menu") + #define HELP_PCH N_("Previous chapter") + #define HELP_NCH N_("Next chapter") + #define HELP_PTR N_("Previous track") + #define HELP_NTR N_("Next track") + + var_Change( p_input, "chapter", VLC_VAR_CHOICESCOUNT, &val, + NULL ); + + if( val.i_int > 0 ) + { + p_main_interface->disc_menu_button->Show(); + p_main_interface->disc_sizer->Show( + p_main_interface->disc_menu_button ); + p_main_interface->disc_sizer->Layout(); + p_main_interface->disc_sizer->Fit( + p_main_interface->disc_frame ); + p_main_interface->disc_menu_button->SetToolTip( + wxU(_( HELP_MENU ) ) ); + p_main_interface->disc_prev_button->SetToolTip( + wxU(_( HELP_PCH ) ) ); + p_main_interface->disc_next_button->SetToolTip( + wxU(_( HELP_NCH ) ) ); + } + else + { + p_main_interface->disc_menu_button->Hide(); + p_main_interface->disc_sizer->Hide( + p_main_interface->disc_menu_button ); + + p_main_interface->disc_prev_button->SetToolTip( + wxU(_( HELP_PTR ) ) ); + p_main_interface->disc_next_button->SetToolTip( + wxU(_( HELP_NTR ) ) ); + } + + p_main_interface->ShowDiscFrame(); + } + else if( val.i_int == 0 && p_main_interface->disc_frame->IsShown() ) + { + p_main_interface->HideDiscFrame(); + } + + + if( pos.f_float > 0.0 && + !p_main_interface->slider_frame->IsShown() ) { - stream_position_t position; + /* Show the slider if it's position is significant */ + p_main_interface->ShowSlider(); + } + else if( pos.f_float <= 0.0 ) + { + p_main_interface->m_slider_timer.Start(200, wxTIMER_ONE_SHOT); + } + if( p_intf->p_sys->b_playing && + p_main_interface->slider_frame->IsShown() ) + { /* Update the slider if the user isn't dragging it. */ if( p_intf->p_sys->b_slider_free ) { + char psz_time[ MSTRTIME_MAX_SIZE ]; + char psz_total[ MSTRTIME_MAX_SIZE ]; + vlc_value_t time; + mtime_t i_seconds; + /* Update the value */ - vlc_mutex_unlock( &p_input->stream.stream_lock ); - input_Tell( p_input, &position ); - vlc_mutex_lock( &p_input->stream.stream_lock ); - if( position.i_size ) + if( pos.f_float >= 0.0 ) { p_intf->p_sys->i_slider_pos = - ( SLIDER_MAX_POS * position.i_tell ) / position.i_size; + (int)(SLIDER_MAX_POS * pos.f_float); p_main_interface->slider->SetValue( p_intf->p_sys->i_slider_pos ); - DisplayStreamDate( p_main_interface->slider_box,p_intf, - p_intf->p_sys->i_slider_pos ); + var_Get( p_intf->p_sys->p_input, "time", &time ); + i_seconds = time.i_time / 1000000; + secstotimestr ( psz_time, i_seconds ); + + var_Get( p_intf->p_sys->p_input, "length", &time ); + i_seconds = time.i_time / 1000000; + secstotimestr ( psz_total, i_seconds ); + + p_main_interface->statusbar->SetStatusText( + wxU(psz_time) + wxString(wxT(" / ")) + + wxU(psz_total), 0 ); } } } - if( p_intf->p_sys->i_part != - p_input->stream.p_selected_area->i_part ) - { - p_intf->p_sys->b_chapter_update = 1; - wxSetupMenus( p_intf ); - } + /* Take care of the volume, etc... */ + p_main_interface->Update(); /* Manage Playing status */ - if( i_old_playing_status != p_input->stream.control.i_status ) + var_Get( p_input, "state", &val ); + if( i_old_playing_status != val.i_int ) { - if( p_input->stream.control.i_status == PAUSE_S ) + if( val.i_int == PAUSE_S ) { p_main_interface->TogglePlayButton( PAUSE_S ); } @@ -237,20 +325,47 @@ void Timer::Notify() { p_main_interface->TogglePlayButton( PLAYING_S ); } - i_old_playing_status = p_input->stream.control.i_status; +#ifdef wxHAS_TASK_BAR_ICON + if( p_main_interface->p_systray ) + { + if( val.i_int == PAUSE_S ) + { + p_main_interface->p_systray->UpdateTooltip( wxU(p_intf->p_sys->p_input->input.p_item->psz_name) + wxString(wxT(" - ")) + wxU(_("Paused"))); + } + else + { + p_main_interface->p_systray->UpdateTooltip( wxU(p_intf->p_sys->p_input->input.p_item->psz_name) + wxString(wxT(" - ")) + wxU(_("Playing"))); + } + } +#endif + i_old_playing_status = val.i_int; } - } - vlc_mutex_unlock( &p_input->stream.stream_lock ); + /* Manage Speed status */ + var_Get( p_input, "rate", &val ); + if( i_old_rate != val.i_int ) + { + p_main_interface->statusbar->SetStatusText( + wxString::Format(wxT("x%.2f"), + (float)INPUT_RATE_DEFAULT / val.i_int ), 1 ); + i_old_rate = val.i_int; + } + } } else if( p_intf->p_sys->b_playing && !p_intf->b_die ) { - wxModeManage( p_intf ); p_intf->p_sys->b_playing = 0; p_main_interface->TogglePlayButton( PAUSE_S ); i_old_playing_status = PAUSE_S; } + /* Show the interface, if requested */ + if( p_intf->p_sys->b_intf_show ) + { + p_main_interface->Raise(); + p_intf->p_sys->b_intf_show = VLC_FALSE; + } + if( p_intf->b_die ) { vlc_mutex_unlock( &p_intf->change_lock ); @@ -264,24 +379,33 @@ void Timer::Notify() } /***************************************************************************** - * DisplayStreamDate: display stream date - ***************************************************************************** - * This function displays the current date related to the position in - * the stream. It is called whenever the slider changes its value. - * The lock has to be taken before you call the function. + * PopupMenuCB: callback triggered by the intf-popupmenu playlist variable. + * We don't show the menu directly here because we don't want the + * caller to block for a too long time. *****************************************************************************/ -void DisplayStreamDate( wxControl *p_slider_frame, intf_thread_t * p_intf , - int i_pos ) +static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable, + vlc_value_t old_val, vlc_value_t new_val, void *param ) { - if( p_intf->p_sys->p_input ) + intf_thread_t *p_intf = (intf_thread_t *)param; + + if( p_intf->p_sys->pf_show_dialog ) { -#define p_area p_intf->p_sys->p_input->stream.p_selected_area - char psz_time[ OFFSETTOTIME_MAX_SIZE ]; - - p_slider_frame->SetLabel( - input_OffsetToTime( p_intf->p_sys->p_input, - psz_time, - p_area->i_size * i_pos / SLIDER_MAX_POS ) ); -#undef p_area - } + p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU, + new_val.b_bool, 0 ); + } + + return VLC_SUCCESS; +} + + +/***************************************************************************** + * IntfShowCB: callback triggered by the intf-show playlist variable. + *****************************************************************************/ +static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable, + vlc_value_t old_val, vlc_value_t new_val, void *param ) +{ + intf_thread_t *p_intf = (intf_thread_t *)param; + p_intf->p_sys->b_intf_show = VLC_TRUE; + + return VLC_SUCCESS; }