Main Page | Modules | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

timer.cpp

00001 /*****************************************************************************
00002  * timer.cpp : wxWindows plugin for vlc
00003  *****************************************************************************
00004  * Copyright (C) 2000-2005 the VideoLAN team
00005  * $Id: timer.cpp 11981 2005-08-03 15:03:23Z xtophe $
00006  *
00007  * Authors: Gildas Bazin <[email protected]>
00008  *
00009  * This program is free software; you can redistribute it and/or modify
00010  * it under the terms of the GNU General Public License as published by
00011  * the Free Software Foundation; either version 2 of the License, or
00012  * (at your option) any later version.
00013  *
00014  * This program is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  * GNU General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU General Public License
00020  * along with this program; if not, write to the Free Software
00021  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
00022  *****************************************************************************/
00023 
00024 /*****************************************************************************
00025  * Preamble
00026  *****************************************************************************/
00027 #include <stdlib.h>                                      /* malloc(), free() */
00028 #include <errno.h>                                                 /* ENOMEM */
00029 #include <string.h>                                            /* strerror() */
00030 #include <stdio.h>
00031 
00032 #include <vlc/vlc.h>
00033 #include <vlc/aout.h>
00034 #include <vlc/intf.h>
00035 
00036 #include "vlc_meta.h"
00037 
00038 #include "wxwidgets.h"
00039 #include <wx/timer.h>
00040 
00041 //void DisplayStreamDate( wxControl *, intf_thread_t *, int );
00042 
00043 /* Callback prototypes */
00044 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
00045                         vlc_value_t old_val, vlc_value_t new_val, void *param );
00046 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
00047                        vlc_value_t old_val, vlc_value_t new_val, void *param );
00048 
00049 /*****************************************************************************
00050  * Constructor.
00051  *****************************************************************************/
00052 Timer::Timer( intf_thread_t *_p_intf, Interface *_p_main_interface )
00053 {
00054     p_intf = _p_intf;
00055     p_main_interface = _p_main_interface;
00056     b_init = 0;
00057     i_old_playing_status = PAUSE_S;
00058     i_old_rate = INPUT_RATE_DEFAULT;
00059 
00060     /* Register callback for the intf-popupmenu variable */
00061     playlist_t *p_playlist =
00062         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
00063                                        FIND_ANYWHERE );
00064     if( p_playlist != NULL )
00065     {
00066         var_AddCallback( p_playlist, "intf-popupmenu", PopupMenuCB, p_intf );
00067         var_AddCallback( p_playlist, "intf-show", IntfShowCB, p_intf );
00068         vlc_object_release( p_playlist );
00069     }
00070 
00071     Start( 100 /*milliseconds*/, wxTIMER_CONTINUOUS );
00072 }
00073 
00074 Timer::~Timer()
00075 {
00076     /* Unregister callback */
00077     playlist_t *p_playlist =
00078         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
00079                                        FIND_ANYWHERE );
00080     if( p_playlist != NULL )
00081     {
00082         var_DelCallback( p_playlist, "intf-popupmenu", PopupMenuCB, p_intf );
00083         var_DelCallback( p_playlist, "intf-show", IntfShowCB, p_intf );
00084         vlc_object_release( p_playlist );
00085     }
00086 
00087     vlc_mutex_lock( &p_intf->change_lock );
00088     if( p_intf->p_sys->p_input ) vlc_object_release( p_intf->p_sys->p_input );
00089     p_intf->p_sys->p_input = NULL;
00090     vlc_mutex_unlock( &p_intf->change_lock );
00091 }
00092 
00093 /*****************************************************************************
00094  * Private methods.
00095  *****************************************************************************/
00096 
00097 /*****************************************************************************
00098  * Manage: manage main thread messages
00099  *****************************************************************************
00100  * In this function, called approx. 10 times a second, we check what the
00101  * main program wanted to tell us.
00102  *****************************************************************************/
00103 void Timer::Notify()
00104 {
00105 #if defined( __WXMSW__ ) /* Work-around a bug with accelerators */
00106     if( !b_init )
00107     {
00108         p_main_interface->Init();
00109         b_init = VLC_TRUE;
00110     }
00111 #endif
00112 
00113     vlc_mutex_lock( &p_intf->change_lock );
00114 
00115     /* Update the input */
00116     if( p_intf->p_sys->p_input == NULL )
00117     {
00118         playlist_t *p_playlist =
00119             (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
00120                                            FIND_ANYWHERE );
00121         if( p_playlist != NULL )
00122         {
00123             LockPlaylist( p_intf->p_sys, p_playlist );
00124             p_intf->p_sys->p_input = p_playlist->p_input;
00125             if( p_intf->p_sys->p_input )
00126                 vlc_object_yield( p_intf->p_sys->p_input );
00127             UnlockPlaylist( p_intf->p_sys, p_playlist );
00128             vlc_object_release( p_playlist );
00129         }
00130 
00131         /* Refresh interface */
00132         if( p_intf->p_sys->p_input )
00133         {
00134             p_main_interface->slider->SetValue( 0 );
00135 
00136             char *psz_now_playing = vlc_input_item_GetInfo(
00137                 p_intf->p_sys->p_input->input.p_item,
00138                 _("Meta-information"), _(VLC_META_NOW_PLAYING) );
00139             if( psz_now_playing && *psz_now_playing )
00140             {
00141                 p_main_interface->statusbar->SetStatusText(
00142                     wxString(wxU(psz_now_playing)) + wxT( " - " ) +
00143                     wxU(p_intf->p_sys->p_input->input.p_item->psz_name), 2 );
00144             }
00145             else
00146             {
00147                 p_main_interface->statusbar->SetStatusText(
00148                     wxU(p_intf->p_sys->p_input->input.p_item->psz_name), 2 );
00149             }
00150             free( psz_now_playing );
00151 
00152             p_main_interface->TogglePlayButton( PLAYING_S );
00153 #ifdef wxHAS_TASK_BAR_ICON
00154             if( p_main_interface->p_systray )
00155             {
00156                 p_main_interface->p_systray->UpdateTooltip( wxU(p_intf->p_sys->p_input->input.p_item->psz_name) + wxString(wxT(" - ")) + wxU(_("Playing")));
00157             }
00158 #endif
00159             i_old_playing_status = PLAYING_S;
00160         }
00161     }
00162     else if( p_intf->p_sys->p_input->b_dead )
00163     {
00164         //controls auto-hide after a timer
00165         p_main_interface->m_controls_timer.Start(200, wxTIMER_ONE_SHOT);
00166 
00167         p_main_interface->TogglePlayButton( PAUSE_S );
00168         i_old_playing_status = PAUSE_S;
00169 
00170         p_main_interface->statusbar->SetStatusText( wxT(""), 0 );
00171         p_main_interface->statusbar->SetStatusText( wxT(""), 2 );
00172 
00173 #ifdef wxHAS_TASK_BAR_ICON
00174         if( p_main_interface->p_systray )
00175         {
00176             p_main_interface->p_systray->UpdateTooltip( wxString(wxT("VLC media player - ")) + wxU(_("Stopped")) );
00177         }
00178 #endif
00179         vlc_object_release( p_intf->p_sys->p_input );
00180         p_intf->p_sys->p_input = NULL;
00181     }
00182 
00183     if( p_intf->p_sys->p_input )
00184     {
00185         input_thread_t *p_input = p_intf->p_sys->p_input;
00186         vlc_value_t val;
00187 
00188         if( !p_input->b_die )
00189         {
00190             vlc_value_t pos;
00191 
00192             //prevent the controls from auto-hiding
00193             p_main_interface->m_controls_timer.Stop();
00194 
00195             /* New input or stream map change */
00196             p_intf->p_sys->b_playing = 1;
00197 
00198             /* Update the item name */
00199             char *psz_now_playing = vlc_input_item_GetInfo(
00200                 p_intf->p_sys->p_input->input.p_item,
00201                 _("Meta-information"), _(VLC_META_NOW_PLAYING) );
00202             if( psz_now_playing && *psz_now_playing )
00203             {
00204                 p_main_interface->statusbar->SetStatusText(
00205                     wxString(wxU(psz_now_playing)) + wxT( " - " ) +
00206                     wxU(p_intf->p_sys->p_input->input.p_item->psz_name), 2 );
00207             }
00208             else
00209             {
00210                 p_main_interface->statusbar->SetStatusText(
00211                     wxU(p_intf->p_sys->p_input->input.p_item->psz_name), 2 );
00212             }
00213             free( psz_now_playing );
00214 
00215             /* Manage the slider */
00216             var_Get( p_input, "position", &pos );
00217 
00218             var_Change( p_input, "title", VLC_VAR_CHOICESCOUNT, &val, NULL );
00219             if( val.i_int > 0 && !p_main_interface->disc_frame->IsShown() )
00220             {
00221                 vlc_value_t val;
00222 
00223                     #define HELP_MENU N_("Menu")
00224                     #define HELP_PCH N_("Previous chapter")
00225                     #define HELP_NCH N_("Next chapter")
00226                     #define HELP_PTR N_("Previous track")
00227                     #define HELP_NTR N_("Next track")
00228 
00229                 var_Change( p_input, "chapter", VLC_VAR_CHOICESCOUNT, &val,
00230                             NULL );
00231 
00232                 if( val.i_int > 0 )
00233                 {
00234                     p_main_interface->disc_menu_button->Show();
00235                     p_main_interface->disc_sizer->Show(
00236                         p_main_interface->disc_menu_button );
00237                     p_main_interface->disc_sizer->Layout();
00238                     p_main_interface->disc_sizer->Fit(
00239                         p_main_interface->disc_frame );
00240                     p_main_interface->disc_menu_button->SetToolTip(
00241                         wxU(_( HELP_MENU ) ) );
00242                     p_main_interface->disc_prev_button->SetToolTip(
00243                         wxU(_( HELP_PCH ) ) );
00244                     p_main_interface->disc_next_button->SetToolTip(
00245                         wxU(_( HELP_NCH ) ) );
00246                 }
00247                 else
00248                 {
00249                     p_main_interface->disc_menu_button->Hide();
00250                     p_main_interface->disc_sizer->Hide(
00251                         p_main_interface->disc_menu_button );
00252 
00253                     p_main_interface->disc_prev_button->SetToolTip(
00254                         wxU(_( HELP_PTR ) ) );
00255                     p_main_interface->disc_next_button->SetToolTip(
00256                         wxU(_( HELP_NTR ) ) );
00257                 }
00258 
00259                 p_main_interface->ShowDiscFrame();
00260             }
00261             else if( val.i_int == 0 && p_main_interface->disc_frame->IsShown() )
00262             {
00263                 p_main_interface->HideDiscFrame();
00264             }
00265 
00266 
00267             if( pos.f_float > 0.0 &&
00268                 !p_main_interface->slider_frame->IsShown() )
00269             {
00270                 /* Show the slider if it's position is significant */
00271                 p_main_interface->ShowSlider();
00272             }
00273             else if( pos.f_float <= 0.0 )
00274             {
00275                 p_main_interface->m_slider_timer.Start(200, wxTIMER_ONE_SHOT);
00276             }
00277 
00278             if( p_intf->p_sys->b_playing &&
00279                 p_main_interface->slider_frame->IsShown() )
00280             {
00281                 /* Update the slider if the user isn't dragging it. */
00282                 if( p_intf->p_sys->b_slider_free )
00283                 {
00284                     char psz_time[ MSTRTIME_MAX_SIZE ];
00285                     char psz_total[ MSTRTIME_MAX_SIZE ];
00286                     vlc_value_t time;
00287                     mtime_t i_seconds;
00288 
00289                     /* Update the value */
00290                     if( pos.f_float >= 0.0 )
00291                     {
00292                         p_intf->p_sys->i_slider_pos =
00293                             (int)(SLIDER_MAX_POS * pos.f_float);
00294 
00295                         p_main_interface->slider->SetValue(
00296                             p_intf->p_sys->i_slider_pos );
00297 
00298                         var_Get( p_intf->p_sys->p_input, "time", &time );
00299                         i_seconds = time.i_time / 1000000;
00300                         secstotimestr ( psz_time, i_seconds );
00301 
00302                         var_Get( p_intf->p_sys->p_input, "length",  &time );
00303                         i_seconds = time.i_time / 1000000;
00304                         secstotimestr ( psz_total, i_seconds );
00305 
00306                         p_main_interface->statusbar->SetStatusText(
00307                             wxU(psz_time) + wxString(wxT(" / ")) +
00308                             wxU(psz_total), 0 );
00309                     }
00310                 }
00311             }
00312 
00313             /* Take care of the volume, etc... */
00314             p_main_interface->Update();
00315 
00316             /* Manage Playing status */
00317             var_Get( p_input, "state", &val );
00318             if( i_old_playing_status != val.i_int )
00319             {
00320                 if( val.i_int == PAUSE_S )
00321                 {
00322                     p_main_interface->TogglePlayButton( PAUSE_S );
00323                 }
00324                 else
00325                 {
00326                     p_main_interface->TogglePlayButton( PLAYING_S );
00327                 }
00328 #ifdef wxHAS_TASK_BAR_ICON
00329                 if( p_main_interface->p_systray )
00330                 {
00331                     if( val.i_int == PAUSE_S )
00332                     {
00333                         p_main_interface->p_systray->UpdateTooltip( wxU(p_intf->p_sys->p_input->input.p_item->psz_name) + wxString(wxT(" - ")) + wxU(_("Paused")));
00334                     }
00335                     else
00336                     {
00337                         p_main_interface->p_systray->UpdateTooltip( wxU(p_intf->p_sys->p_input->input.p_item->psz_name) + wxString(wxT(" - ")) + wxU(_("Playing")));
00338                     }
00339                 }
00340 #endif
00341                 i_old_playing_status = val.i_int;
00342             }
00343 
00344             /* Manage Speed status */
00345             var_Get( p_input, "rate", &val );
00346             if( i_old_rate != val.i_int )
00347             {
00348                 p_main_interface->statusbar->SetStatusText(
00349                     wxString::Format(wxT("x%.2f"),
00350                     (float)INPUT_RATE_DEFAULT / val.i_int ), 1 );
00351                 i_old_rate = val.i_int;
00352             }
00353         }
00354     }
00355     else if( p_intf->p_sys->b_playing && !p_intf->b_die )
00356     {
00357         p_intf->p_sys->b_playing = 0;
00358         p_main_interface->TogglePlayButton( PAUSE_S );
00359         i_old_playing_status = PAUSE_S;
00360     }
00361 
00362     /* Show the interface, if requested */
00363     if( p_intf->p_sys->b_intf_show )
00364     {
00365         p_main_interface->Raise();
00366         p_intf->p_sys->b_intf_show = VLC_FALSE;
00367     }
00368 
00369     if( p_intf->b_die )
00370     {
00371         vlc_mutex_unlock( &p_intf->change_lock );
00372 
00373         /* Prepare to die, young Skywalker */
00374         p_main_interface->Close(TRUE);
00375         return;
00376     }
00377 
00378     vlc_mutex_unlock( &p_intf->change_lock );
00379 }
00380 
00381 /*****************************************************************************
00382  * PopupMenuCB: callback triggered by the intf-popupmenu playlist variable.
00383  *  We don't show the menu directly here because we don't want the
00384  *  caller to block for a too long time.
00385  *****************************************************************************/
00386 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
00387                         vlc_value_t old_val, vlc_value_t new_val, void *param )
00388 {
00389     intf_thread_t *p_intf = (intf_thread_t *)param;
00390 
00391     if( p_intf->p_sys->pf_show_dialog )
00392     {
00393         p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU,
00394                                        new_val.b_bool, 0 );
00395     }
00396 
00397     return VLC_SUCCESS;
00398 }
00399 
00400 
00401 /*****************************************************************************
00402  * IntfShowCB: callback triggered by the intf-show playlist variable.
00403  *****************************************************************************/
00404 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
00405                        vlc_value_t old_val, vlc_value_t new_val, void *param )
00406 {
00407     intf_thread_t *p_intf = (intf_thread_t *)param;
00408     p_intf->p_sys->b_intf_show = VLC_TRUE;
00409 
00410     return VLC_SUCCESS;
00411 }

Generated on Tue Dec 20 10:14:46 2005 for vlc-0.8.4a by  doxygen 1.4.2