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

timer.cpp

00001 /*****************************************************************************
00002  * timer.cpp : WinCE gui plugin for VLC
00003  *****************************************************************************
00004  * Copyright (C) 2000-2003 the VideoLAN team
00005  * $Id: timer.cpp 11664 2005-07-09 06:17:09Z courmisch $
00006  *
00007  * Authors: Marodon Cedric <[email protected]>
00008  *          Gildas Bazin <[email protected]>
00009  *
00010  * This program is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2 of the License, or
00013  * (at your option) any later version.
00014  *
00015  * This program is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  * GNU General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU General Public License
00021  * along with this program; if not, write to the Free Software
00022  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
00023  *****************************************************************************/
00024 
00025 /*****************************************************************************
00026  * Preamble
00027  *****************************************************************************/
00028 #include <stdlib.h>                                      /* malloc(), free() */
00029 #include <string.h>                                            /* strerror() */
00030 #include <stdio.h>
00031 #include <vlc/vlc.h>
00032 #include <vlc/aout.h>
00033 #include <vlc/intf.h>
00034 
00035 #include "wince.h"
00036 
00037 #include <commctrl.h>
00038 
00039 /* Callback prototype */
00040 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
00041                         vlc_value_t old_val, vlc_value_t new_val, void * );
00042 
00043 /*****************************************************************************
00044  * Constructor.
00045  *****************************************************************************/
00046 Timer::Timer( intf_thread_t *_p_intf, HWND hwnd, Interface *_p_main_interface)
00047 {
00048     p_intf = _p_intf;
00049     p_main_interface = _p_main_interface;
00050     i_old_playing_status = PAUSE_S;
00051     i_old_rate = INPUT_RATE_DEFAULT;
00052 
00053     /* Register callback for the intf-popupmenu variable */
00054     playlist_t *p_playlist =
00055         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
00056                                        FIND_ANYWHERE );
00057     if( p_playlist != NULL )
00058     {
00059         var_AddCallback( p_playlist, "intf-popupmenu", PopupMenuCB, p_intf );
00060         vlc_object_release( p_playlist );
00061     }
00062 
00063     SetTimer( hwnd, 1, 200 /*milliseconds*/, NULL );
00064 }
00065 
00066 Timer::~Timer()
00067 {
00068     /* Unregister callback */
00069     playlist_t *p_playlist =
00070         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
00071                                        FIND_ANYWHERE );
00072     if( p_playlist != NULL )
00073     {
00074         var_DelCallback( p_playlist, "intf-popupmenu", PopupMenuCB, p_intf );
00075         vlc_object_release( p_playlist );
00076     }
00077 }
00078 
00079 /*****************************************************************************
00080  * Private methods.
00081  *****************************************************************************/
00082 
00083 /*****************************************************************************
00084  * Manage: manage main thread messages
00085  *****************************************************************************
00086  * In this function, called approx. 10 times a second, we check what the
00087  * main program wanted to tell us.
00088  *****************************************************************************/
00089 void Timer::Notify( void )
00090 {
00091     vlc_value_t val;
00092     char *shortname;
00093 
00094     vlc_mutex_lock( &p_intf->change_lock );
00095 
00096     /* Update the input */
00097     if( p_intf->p_sys->p_input == NULL )
00098     {
00099         p_intf->p_sys->p_input =
00100             (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
00101                                                FIND_ANYWHERE );
00102 
00103         /* Show slider */
00104         if( p_intf->p_sys->p_input )
00105         {
00106             ShowWindow( p_main_interface->hwndSlider, SW_SHOW );
00107             ShowWindow( p_main_interface->hwndLabel, SW_SHOW );
00108             ShowWindow( p_main_interface->hwndVol, SW_SHOW );
00109 
00110             // only for local file, check if works well with net url
00111             shortname = strrchr( p_intf->p_sys->p_input->input.p_item->psz_name, '\\' );
00112             if (! shortname)
00113                 shortname = p_intf->p_sys->p_input->input.p_item->psz_name;
00114             else shortname++;
00115                         
00116             SendMessage( p_main_interface->hwndSB, SB_SETTEXT, 
00117                          (WPARAM) 0, (LPARAM)_FROMMB(shortname) );
00118 
00119             p_main_interface->TogglePlayButton( PLAYING_S );
00120             i_old_playing_status = PLAYING_S;
00121         }
00122     }
00123     else if( p_intf->p_sys->p_input->b_dead )
00124     {
00125         /* Hide slider */
00126         ShowWindow( p_main_interface->hwndSlider, SW_HIDE);
00127         ShowWindow( p_main_interface->hwndLabel, SW_HIDE);
00128         ShowWindow( p_main_interface->hwndVol, SW_HIDE);
00129 
00130         p_main_interface->TogglePlayButton( PAUSE_S );
00131         i_old_playing_status = PAUSE_S;
00132 
00133         SendMessage( p_main_interface->hwndSB, SB_SETTEXT, 
00134                      (WPARAM) 0, (LPARAM)(LPCTSTR) TEXT(""));
00135 
00136         vlc_object_release( p_intf->p_sys->p_input );
00137         p_intf->p_sys->p_input = NULL;
00138     }
00139 
00140     if( p_intf->p_sys->p_input )
00141     {
00142         input_thread_t *p_input = p_intf->p_sys->p_input;
00143 
00144         if( !p_input->b_die )
00145         {
00146             /* New input or stream map change */
00147             p_intf->p_sys->b_playing = 1;
00148 
00149             /* Manage the slider */
00150             if( /*p_input->stream.b_seekable &&*/ p_intf->p_sys->b_playing )
00151             {
00152                 /* Update the slider if the user isn't dragging it. */
00153                 if( p_intf->p_sys->b_slider_free )
00154                 {
00155                     vlc_value_t pos;
00156                     char psz_time[ MSTRTIME_MAX_SIZE ];
00157                     vlc_value_t time;
00158                     mtime_t i_seconds;
00159 
00160                     /* Update the value */
00161                     var_Get( p_input, "position", &pos );
00162                     if( pos.f_float >= 0.0 )
00163                     {
00164                         p_intf->p_sys->i_slider_pos =
00165                             (int)(SLIDER_MAX_POS * pos.f_float);
00166 
00167                         SendMessage( p_main_interface->hwndSlider, TBM_SETPOS, 
00168                                      1, p_intf->p_sys->i_slider_pos );
00169 
00170                         var_Get( p_intf->p_sys->p_input, "time", &time );
00171                         i_seconds = time.i_time / 1000000;
00172                         secstotimestr ( psz_time, i_seconds );
00173 
00174                         SendMessage( p_main_interface->hwndLabel, WM_SETTEXT, 
00175                                      (WPARAM)1, (LPARAM)_FROMMB(psz_time) );
00176                     }
00177                 }
00178             }
00179 
00180             /* Take care of the volume, etc... */
00181             p_main_interface->Update();
00182 
00183             /* Manage Playing status */
00184             var_Get( p_input, "state", &val );
00185             if( i_old_playing_status != val.i_int )
00186             {
00187                 if( val.i_int == PAUSE_S )
00188                 {
00189                     p_main_interface->TogglePlayButton( PAUSE_S );
00190                 }
00191                 else
00192                 {
00193                     p_main_interface->TogglePlayButton( PLAYING_S );
00194                 }
00195                 i_old_playing_status = val.i_int;
00196             }
00197 
00198             /* Manage Speed status */
00199             var_Get( p_input, "rate", &val );
00200             if( i_old_rate != val.i_int )
00201             {
00202                 TCHAR psz_text[15];
00203                 _stprintf( psz_text + 2, _T("x%.2f"), 1000.0 / val.i_int );
00204                 psz_text[0] = psz_text[1] = _T('\t');
00205 
00206                 SendMessage( p_main_interface->hwndSB, SB_SETTEXT, 
00207                              (WPARAM) 1, (LPARAM)(LPCTSTR) psz_text );
00208 
00209                 i_old_rate = val.i_int;
00210             }
00211         }
00212     }
00213     else if( p_intf->p_sys->b_playing && !p_intf->b_die )
00214     {
00215         p_intf->p_sys->b_playing = 0;
00216         p_main_interface->TogglePlayButton( PAUSE_S );
00217         i_old_playing_status = PAUSE_S;
00218     }
00219 
00220     if( p_intf->b_die )
00221     {
00222         vlc_mutex_unlock( &p_intf->change_lock );
00223 
00224         /* Prepare to die, young Skywalker */
00225 /*        p_main_interface->Close(TRUE);*/
00226         return;
00227     }
00228 
00229     vlc_mutex_unlock( &p_intf->change_lock );
00230 }
00231 
00232 /*****************************************************************************
00233  * PopupMenuCB: callback triggered by the intf-popupmenu playlist variable.
00234  *  We don't show the menu directly here because we don't want the
00235  *  caller to block for a too long time.
00236  *****************************************************************************/
00237 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
00238                         vlc_value_t old_val, vlc_value_t new_val, void *param )
00239 {
00240     intf_thread_t *p_intf = (intf_thread_t *)param;
00241 
00242     if( p_intf->p_sys->pf_show_dialog )
00243     {
00244         p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU,
00245                                        new_val.b_bool, 0 );
00246     }
00247 
00248     return VLC_SUCCESS;
00249 }

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