]> git.sesse.net Git - vlc/blob - modules/gui/wxwidgets/timer.cpp
e8514be145c4c148b88a0d9ac7a4e151f2e55580
[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 "input_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     /* Register callback for the intf-popupmenu variable */
50     playlist_t *p_playlist =
51         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
52                                        FIND_ANYWHERE );
53     if( p_playlist != NULL )
54     {
55         var_AddCallback( p_playlist, "intf-popupmenu", PopupMenuCB, p_intf );
56         var_AddCallback( p_playlist, "intf-show", IntfShowCB, p_intf );
57         vlc_object_release( p_playlist );
58     }
59
60     Start( 100 /*milliseconds*/, wxTIMER_CONTINUOUS );
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         var_DelCallback( p_playlist, "intf-show", IntfShowCB, p_intf );
73         vlc_object_release( p_playlist );
74     }
75 }
76
77 /*****************************************************************************
78  * Private methods.
79  *****************************************************************************/
80
81 /*****************************************************************************
82  * Manage: manage main thread messages
83  *****************************************************************************
84  * In this function, called approx. 10 times a second, we check what the
85  * main program wanted to tell us.
86  *****************************************************************************/
87 void Timer::Notify()
88 {
89 #if defined( __WXMSW__ ) /* Work-around a bug with accelerators */
90     if( !b_init )
91     {
92         p_main_interface->Init();
93         b_init = VLC_TRUE;
94     }
95 #endif
96
97     vlc_mutex_lock( &p_intf->change_lock );
98
99     /* Call update */
100     p_main_interface->input_manager->Update();
101
102     if( p_main_interface->input_manager->IsPlaying() )
103     {
104         /* Take care of the volume, etc... */
105         p_main_interface->Update();
106     }
107
108     /* Show the interface, if requested */
109     if( p_intf->p_sys->b_intf_show )
110     {
111         p_main_interface->Raise();
112         p_intf->p_sys->b_intf_show = VLC_FALSE;
113     }
114
115     if( p_intf->b_die )
116     {
117         vlc_mutex_unlock( &p_intf->change_lock );
118
119         /* Prepare to die, young Skywalker */
120         p_main_interface->Close(TRUE);
121         return;
122     }
123
124     vlc_mutex_unlock( &p_intf->change_lock );
125 }
126
127 /*****************************************************************************
128  * PopupMenuCB: callback triggered by the intf-popupmenu playlist variable.
129  *  We don't show the menu directly here because we don't want the
130  *  caller to block for a too long time.
131  *****************************************************************************/
132 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
133                         vlc_value_t old_val, vlc_value_t new_val, void *param )
134 {
135     intf_thread_t *p_intf = (intf_thread_t *)param;
136
137     if( p_intf->p_sys->pf_show_dialog )
138     {
139         p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU,
140                                        new_val.b_bool, 0 );
141     }
142
143     return VLC_SUCCESS;
144 }
145
146
147 /*****************************************************************************
148  * IntfShowCB: callback triggered by the intf-show playlist variable.
149  *****************************************************************************/
150 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
151                        vlc_value_t old_val, vlc_value_t new_val, void *param )
152 {
153     intf_thread_t *p_intf = (intf_thread_t *)param;
154     p_intf->p_sys->b_intf_show = VLC_TRUE;
155
156     return VLC_SUCCESS;
157 }