]> git.sesse.net Git - vlc/blob - modules/gui/wince/timer.cpp
0562dcb660247d8341937fb1a401eef3356dc1eb
[vlc] / modules / gui / wince / timer.cpp
1 /*****************************************************************************
2  * timer.cpp : WinCE gui plugin for VLC
3  *****************************************************************************
4  * Copyright (C) 2000-2003 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Marodon Cedric <cedric_marodon@yahoo.fr>
8  *          Gildas Bazin <gbazin@videolan.org>
9  *
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.
14  *
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.
19  *
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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23  *****************************************************************************/
24
25 /*****************************************************************************
26  * Preamble
27  *****************************************************************************/
28 #include <vlc/vlc.h>
29 #include <vlc_aout.h>
30 #include <vlc_interface.h>
31
32 #include "wince.h"
33
34 #include <commctrl.h>
35
36 /* Callback prototype */
37 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
38                         vlc_value_t old_val, vlc_value_t new_val, void * );
39
40 /*****************************************************************************
41  * Constructor.
42  *****************************************************************************/
43 Timer::Timer( intf_thread_t *_p_intf, HWND hwnd, Interface *_p_main_interface)
44 {
45     p_intf = _p_intf;
46     p_main_interface = _p_main_interface;
47     i_old_playing_status = PAUSE_S;
48     i_old_rate = INPUT_RATE_DEFAULT;
49
50     /* Register callback for the intf-popupmenu variable */
51     playlist_t *p_playlist =
52         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
53                                        FIND_ANYWHERE );
54     if( p_playlist != NULL )
55     {
56         var_AddCallback( p_playlist, "intf-popupmenu", PopupMenuCB, p_intf );
57         vlc_object_release( p_playlist );
58     }
59
60     SetTimer( hwnd, 1, 200 /*milliseconds*/, NULL );
61 }
62
63 Timer::~Timer()
64 {
65     /* Unregister callback */
66     playlist_t *p_playlist =
67         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
68                                        FIND_ANYWHERE );
69     if( p_playlist != NULL )
70     {
71         var_DelCallback( p_playlist, "intf-popupmenu", PopupMenuCB, p_intf );
72         vlc_object_release( p_playlist );
73     }
74 }
75
76 /*****************************************************************************
77  * Private methods.
78  *****************************************************************************/
79
80 /*****************************************************************************
81  * Manage: manage main thread messages
82  *****************************************************************************
83  * In this function, called approx. 10 times a second, we check what the
84  * main program wanted to tell us.
85  *****************************************************************************/
86 void Timer::Notify( void )
87 {
88     vlc_value_t val;
89     char *shortname;
90
91     vlc_mutex_lock( &p_intf->change_lock );
92
93     /* Update the input */
94     if( p_intf->p_sys->p_input == NULL )
95     {
96         p_intf->p_sys->p_input =
97             (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
98                                                FIND_ANYWHERE );
99
100         /* Show slider */
101         if( p_intf->p_sys->p_input )
102         {
103             ShowWindow( p_main_interface->hwndSlider, SW_SHOW );
104             ShowWindow( p_main_interface->hwndLabel, SW_SHOW );
105             ShowWindow( p_main_interface->hwndVol, SW_SHOW );
106
107             // only for local file, check if works well with net url
108             shortname = strrchr( p_intf->p_sys->p_input->input.p_item->psz_name, '\\' );
109             if (! shortname)
110                 shortname = p_intf->p_sys->p_input->input.p_item->psz_name;
111             else shortname++;
112                         
113             SendMessage( p_main_interface->hwndSB, SB_SETTEXT, 
114                          (WPARAM) 0, (LPARAM)_FROMMB(shortname) );
115
116             p_main_interface->TogglePlayButton( PLAYING_S );
117             i_old_playing_status = PLAYING_S;
118         }
119     }
120     else if( p_intf->p_sys->p_input->b_dead )
121     {
122         /* Hide slider */
123         ShowWindow( p_main_interface->hwndSlider, SW_HIDE);
124         ShowWindow( p_main_interface->hwndLabel, SW_HIDE);
125         ShowWindow( p_main_interface->hwndVol, SW_HIDE);
126
127         p_main_interface->TogglePlayButton( PAUSE_S );
128         i_old_playing_status = PAUSE_S;
129
130         SendMessage( p_main_interface->hwndSB, SB_SETTEXT, 
131                      (WPARAM) 0, (LPARAM)(LPCTSTR) TEXT(""));
132
133         vlc_object_release( p_intf->p_sys->p_input );
134         p_intf->p_sys->p_input = NULL;
135     }
136
137     if( p_intf->p_sys->p_input )
138     {
139         input_thread_t *p_input = p_intf->p_sys->p_input;
140
141         if( !p_input->b_die )
142         {
143             /* New input or stream map change */
144             p_intf->p_sys->b_playing = 1;
145
146             /* Manage the slider */
147             if( /*p_input->stream.b_seekable &&*/ p_intf->p_sys->b_playing )
148             {
149                 /* Update the slider if the user isn't dragging it. */
150                 if( p_intf->p_sys->b_slider_free )
151                 {
152                     vlc_value_t pos;
153                     char psz_time[ MSTRTIME_MAX_SIZE ];
154                     vlc_value_t time;
155                     mtime_t i_seconds;
156
157                     /* Update the value */
158                     var_Get( p_input, "position", &pos );
159                     if( pos.f_float >= 0.0 )
160                     {
161                         p_intf->p_sys->i_slider_pos =
162                             (int)(SLIDER_MAX_POS * pos.f_float);
163
164                         SendMessage( p_main_interface->hwndSlider, TBM_SETPOS, 
165                                      1, p_intf->p_sys->i_slider_pos );
166
167                         var_Get( p_intf->p_sys->p_input, "time", &time );
168                         i_seconds = time.i_time / 1000000;
169                         secstotimestr ( psz_time, i_seconds );
170
171                         SendMessage( p_main_interface->hwndLabel, WM_SETTEXT, 
172                                      (WPARAM)1, (LPARAM)_FROMMB(psz_time) );
173                     }
174                 }
175             }
176
177             /* Take care of the volume, etc... */
178             p_main_interface->Update();
179
180             /* Manage Playing status */
181             var_Get( p_input, "state", &val );
182             if( i_old_playing_status != val.i_int )
183             {
184                 if( val.i_int == PAUSE_S )
185                 {
186                     p_main_interface->TogglePlayButton( PAUSE_S );
187                 }
188                 else
189                 {
190                     p_main_interface->TogglePlayButton( PLAYING_S );
191                 }
192                 i_old_playing_status = val.i_int;
193             }
194
195             /* Manage Speed status */
196             var_Get( p_input, "rate", &val );
197             if( i_old_rate != val.i_int )
198             {
199                 TCHAR psz_text[15];
200                 _stprintf( psz_text + 2, _T("x%.2f"), 1000.0 / val.i_int );
201                 psz_text[0] = psz_text[1] = _T('\t');
202
203                 SendMessage( p_main_interface->hwndSB, SB_SETTEXT, 
204                              (WPARAM) 1, (LPARAM)(LPCTSTR) psz_text );
205
206                 i_old_rate = val.i_int;
207             }
208         }
209     }
210     else if( p_intf->p_sys->b_playing && !intf_ShouldDie( p_intf ) )
211     {
212         p_intf->p_sys->b_playing = 0;
213         p_main_interface->TogglePlayButton( PAUSE_S );
214         i_old_playing_status = PAUSE_S;
215     }
216
217     if( intf_ShouldDie( p_intf ) )
218     {
219         vlc_mutex_unlock( &p_intf->change_lock );
220
221         /* Prepare to die, young Skywalker */
222 /*        p_main_interface->Close(TRUE);*/
223         return;
224     }
225
226     vlc_mutex_unlock( &p_intf->change_lock );
227 }
228
229 /*****************************************************************************
230  * PopupMenuCB: callback triggered by the intf-popupmenu playlist variable.
231  *  We don't show the menu directly here because we don't want the
232  *  caller to block for a too long time.
233  *****************************************************************************/
234 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
235                         vlc_value_t old_val, vlc_value_t new_val, void *param )
236 {
237     intf_thread_t *p_intf = (intf_thread_t *)param;
238
239     if( p_intf->p_sys->pf_show_dialog )
240     {
241         p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU,
242                                        new_val.b_bool, 0 );
243     }
244
245     return VLC_SUCCESS;
246 }