]> git.sesse.net Git - vlc/blob - modules/gui/wxwidgets/timer.cpp
p( vlc.getInterfaces().getInterface( "wxwidgets" ).isBroken() ) = 1/2
[vlc] / modules / gui / wxwidgets / timer.cpp
1 /*****************************************************************************
2  * timer.cpp : wxWindows plugin for vlc
3  *****************************************************************************
4  * Copyright (C) 2000-2005 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Gildas Bazin <gbazin@videolan.org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #include "timer.hpp"
28 #include "main_slider_manager.hpp"
29 #include "interface.hpp"
30 #include "vlc_meta.h"
31
32 //void DisplayStreamDate( wxControl *, intf_thread_t *, int );
33
34 /* Callback prototypes */
35 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
36                         vlc_value_t old_val, vlc_value_t new_val, void *param );
37 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
38                        vlc_value_t old_val, vlc_value_t new_val, void *param );
39
40 /*****************************************************************************
41  * Constructor.
42  *****************************************************************************/
43 Timer::Timer( intf_thread_t *_p_intf, Interface *_p_main_interface )
44 {
45     p_intf = _p_intf;
46     p_main_interface = _p_main_interface;
47     b_init = 0;
48
49     msm = new MainSliderManager( p_intf, p_main_interface );
50
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         var_AddCallback( p_playlist, "intf-show", IntfShowCB, p_intf );
62         vlc_object_release( p_playlist );
63     }
64
65     Start( 100 /*milliseconds*/, wxTIMER_CONTINUOUS );
66 }
67
68 Timer::~Timer()
69 {
70     /* Unregister callback */
71     playlist_t *p_playlist =
72         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
73                                        FIND_ANYWHERE );
74     if( p_playlist != NULL )
75     {
76         var_DelCallback( p_playlist, "intf-popupmenu", PopupMenuCB, p_intf );
77         var_DelCallback( p_playlist, "intf-show", IntfShowCB, p_intf );
78         vlc_object_release( p_playlist );
79     }
80
81     delete msm;
82 }
83
84 /*****************************************************************************
85  * Private methods.
86  *****************************************************************************/
87
88 /*****************************************************************************
89  * Manage: manage main thread messages
90  *****************************************************************************
91  * In this function, called approx. 10 times a second, we check what the
92  * main program wanted to tell us.
93  *****************************************************************************/
94 void Timer::Notify()
95 {
96 #if defined( __WXMSW__ ) /* Work-around a bug with accelerators */
97     if( !b_init )
98     {
99         p_main_interface->Init();
100         b_init = VLC_TRUE;
101     }
102 #endif
103
104     vlc_mutex_lock( &p_intf->change_lock );
105
106     /* Call update */
107     msm->Update();
108
109     vlc_value_t val;
110     input_thread_t *p_input = p_intf->p_sys->p_input;
111     if( p_intf->p_sys->p_input )
112     {
113         if( !p_intf->p_sys->p_input->b_die )
114         {
115             /* Take care of the volume, etc... */
116             p_main_interface->Update();
117
118             /* Manage Playing status */
119             var_Get( p_input, "state", &val );
120             if( i_old_playing_status != val.i_int )
121             {
122                 if( val.i_int == PAUSE_S )
123                 {
124                     p_main_interface->TogglePlayButton( PAUSE_S );
125                 }
126                 else
127                 {
128                     p_main_interface->TogglePlayButton( PLAYING_S );
129                 }
130 #ifdef wxHAS_TASK_BAR_ICON
131                 if( p_main_interface->p_systray )
132                 {
133                     if( val.i_int == PAUSE_S )
134                     {
135                         p_main_interface->p_systray->UpdateTooltip( wxU(p_intf->p_sys->p_input->input.p_item->psz_name) + wxString(wxT(" - ")) + wxU(_("Paused")));
136                     }
137                     else
138                     {
139                         p_main_interface->p_systray->UpdateTooltip( wxU(p_intf->p_sys->p_input->input.p_item->psz_name) + wxString(wxT(" - ")) + wxU(_("Playing")));
140                     }
141                 }
142 #endif
143                 i_old_playing_status = val.i_int;
144             }
145
146             /* Manage Speed status */
147             var_Get( p_input, "rate", &val );
148             if( i_old_rate != val.i_int )
149             {
150                 p_main_interface->statusbar->SetStatusText(
151                     wxString::Format(wxT("x%.2f"),
152                     (float)INPUT_RATE_DEFAULT / val.i_int ), 1 );
153                 i_old_rate = val.i_int;
154             }
155         }
156     }
157     else if( p_intf->p_sys->b_playing && !p_intf->b_die )
158     {
159         p_intf->p_sys->b_playing = 0;
160         p_main_interface->TogglePlayButton( PAUSE_S );
161         i_old_playing_status = PAUSE_S;
162     }
163
164     /* Show the interface, if requested */
165     if( p_intf->p_sys->b_intf_show )
166     {
167         p_main_interface->Raise();
168         p_intf->p_sys->b_intf_show = VLC_FALSE;
169     }
170
171     if( p_intf->b_die )
172     {
173         vlc_mutex_unlock( &p_intf->change_lock );
174
175         /* Prepare to die, young Skywalker */
176         p_main_interface->Close(TRUE);
177         return;
178     }
179
180     vlc_mutex_unlock( &p_intf->change_lock );
181 }
182
183 /*****************************************************************************
184  * PopupMenuCB: callback triggered by the intf-popupmenu playlist variable.
185  *  We don't show the menu directly here because we don't want the
186  *  caller to block for a too long time.
187  *****************************************************************************/
188 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
189                         vlc_value_t old_val, vlc_value_t new_val, void *param )
190 {
191     intf_thread_t *p_intf = (intf_thread_t *)param;
192
193     if( p_intf->p_sys->pf_show_dialog )
194     {
195         p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU,
196                                        new_val.b_bool, 0 );
197     }
198
199     return VLC_SUCCESS;
200 }
201
202
203 /*****************************************************************************
204  * IntfShowCB: callback triggered by the intf-show playlist variable.
205  *****************************************************************************/
206 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
207                        vlc_value_t old_val, vlc_value_t new_val, void *param )
208 {
209     intf_thread_t *p_intf = (intf_thread_t *)param;
210     p_intf->p_sys->b_intf_show = VLC_TRUE;
211
212     return VLC_SUCCESS;
213 }