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