]> git.sesse.net Git - vlc/blob - modules/gui/hildon/maemo_input.c
macosx: disable extensions submenu when they are no items to display
[vlc] / modules / gui / hildon / maemo_input.c
1 /*****************************************************************************
2  * maemo_input.c : Input handling for the maemo plugin
3  *****************************************************************************
4  * Copyright (C) 2008 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Antoine Lejeune <phytos@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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 #ifdef HAVE_CONFIG_H
25 # include "config.h"
26 #endif
27
28 #include <vlc_common.h>
29
30 #include "maemo.h"
31 #include "maemo_input.h"
32
33 /*****************************************************************************
34  * Local prototypes.
35  *****************************************************************************/
36 static void update_position( intf_thread_t *p_intf );
37 static void item_changed( intf_thread_t *p_intf );
38 static void item_changed_pl( intf_thread_t *p_intf );
39
40 static int input_event_cb( vlc_object_t *p_this, const char *psz_var,
41                            vlc_value_t oldval, vlc_value_t newval, void *param );
42 static int interface_changed_cb( vlc_object_t *p_this, const char *psz_var,
43                                  vlc_value_t oldval, vlc_value_t newval,
44                                  void *param );
45 static gboolean process_events( gpointer data );
46
47 void set_input( intf_thread_t *p_intf, input_thread_t *p_input );
48 void delete_input( intf_thread_t *p_intf );
49
50
51
52 /*****************************************************************************
53  * Functions.
54  *****************************************************************************/
55 void post_event( intf_thread_t *p_intf, int i_event )
56 {
57     vlc_spin_lock( &p_intf->p_sys->event_lock );
58     p_intf->p_sys->i_event |= i_event;
59     vlc_spin_unlock( &p_intf->p_sys->event_lock );
60     g_idle_add( process_events, p_intf );
61 }
62
63 static gboolean process_events( gpointer data )
64 {
65     intf_thread_t *p_intf = (intf_thread_t *)data;
66     int i_event;
67
68     vlc_spin_lock( &p_intf->p_sys->event_lock );
69     i_event = p_intf->p_sys->i_event;
70     p_intf->p_sys->i_event = 0;
71     vlc_spin_unlock( &p_intf->p_sys->event_lock );
72
73     if( !i_event ) return TRUE;
74
75     if( i_event & EVENT_PLAYLIST_CURRENT )
76         item_changed_pl( p_intf );
77     if( i_event & EVENT_ACTIVITY )
78         item_changed_pl( p_intf );
79     if( i_event & EVENT_ITEM_CHANGED )
80         item_changed( p_intf );
81     if( i_event & EVENT_INTF_CHANGED )
82         update_position( p_intf );
83
84     return FALSE;
85 }
86
87 void set_input( intf_thread_t *p_intf, input_thread_t *p_input )
88 {
89     if( p_input && !( p_input->b_die || p_input->b_dead ) )
90     {
91         p_intf->p_sys->p_input = p_input;
92         vlc_object_hold( p_input );
93         var_AddCallback( p_input, "intf-event", input_event_cb, p_intf );
94
95         // "Activate" the seekbar
96         gtk_widget_set_sensitive( GTK_WIDGET( p_intf->p_sys->p_seekbar ), TRUE );
97     }
98     else
99         p_intf->p_sys->p_input = NULL;
100 }
101
102 void delete_input( intf_thread_t *p_intf )
103 {
104     if( p_intf->p_sys->p_input )
105     {
106         var_DelCallback( p_intf->p_sys->p_input, "intf-event",
107                          input_event_cb, p_intf );
108         vlc_object_release( p_intf->p_sys->p_input );
109         p_intf->p_sys->p_input = NULL;
110
111         // Reset the seekbar
112         hildon_seekbar_set_position( p_intf->p_sys->p_seekbar, 0 );
113         gtk_widget_set_sensitive( GTK_WIDGET( p_intf->p_sys->p_seekbar ), FALSE );
114     }
115 }
116
117 static void item_changed_pl( intf_thread_t *p_intf )
118 {
119     if( p_intf->p_sys->p_input &&
120         ( p_intf->p_sys->p_input->b_dead || p_intf->p_sys->p_input->b_die ) )
121     {
122         delete_input( p_intf );
123         return;
124     }
125
126     if( !p_intf->p_sys->p_input )
127     {
128         set_input( p_intf, playlist_CurrentInput( p_intf->p_sys->p_playlist ) );
129     }
130     return;
131 }
132
133 int playlist_current_cb( vlc_object_t *p_this, const char *psz_var,
134                          vlc_value_t oldval, vlc_value_t newval, void *param )
135 {
136     intf_thread_t *p_intf = (intf_thread_t *)param;
137     (void)p_this; (void)psz_var; (void)oldval; (void)newval;
138
139     vlc_spin_lock( &p_intf->p_sys->event_lock );
140     p_intf->p_sys->i_event |= EVENT_PLAYLIST_CURRENT;
141     vlc_spin_unlock( &p_intf->p_sys->event_lock );
142     g_idle_add( process_events, p_intf );
143     return VLC_SUCCESS;
144 }
145
146 int activity_cb( vlc_object_t *p_this, const char *psz_var,
147                  vlc_value_t oldval, vlc_value_t newval, void *param )
148 {
149     intf_thread_t *p_intf = (intf_thread_t *)param;
150     (void)p_this; (void)psz_var; (void)oldval; (void)newval;
151
152     vlc_spin_lock( &p_intf->p_sys->event_lock );
153     p_intf->p_sys->i_event |= EVENT_ACTIVITY;
154     vlc_spin_unlock( &p_intf->p_sys->event_lock );
155     g_idle_add( process_events, p_intf );
156     return VLC_SUCCESS;
157 }
158
159 static void item_changed( intf_thread_t *p_intf )
160 {
161     GtkButton *p_button = GTK_BUTTON( p_intf->p_sys->p_play_button );
162     vlc_value_t state;
163
164     if( !p_intf->p_sys->p_input )
165         return;
166
167     var_Get( p_intf->p_sys->p_input, "state", &state );
168
169     // We change the "play" button
170     if( state.i_int == PLAYING_S )
171         gtk_button_set_image( p_button, gtk_image_new_from_stock( "vlc-pause",
172                               GTK_ICON_SIZE_BUTTON ) );
173     else
174         gtk_button_set_image( p_button, gtk_image_new_from_stock( "vlc-play",
175                               GTK_ICON_SIZE_BUTTON ) );
176 }
177
178 int item_changed_cb( vlc_object_t *p_this, const char *psz_var,
179                      vlc_value_t oldval, vlc_value_t newval, void *param )
180 {
181     (void)p_this; (void)psz_var; (void)oldval; (void)newval;
182     intf_thread_t *p_intf = (intf_thread_t *)param;
183
184     vlc_spin_lock( &p_intf->p_sys->event_lock );
185     p_intf->p_sys->i_event |= EVENT_ITEM_CHANGED;
186     vlc_spin_unlock( &p_intf->p_sys->event_lock );
187     g_idle_add( process_events, p_intf );
188     return VLC_SUCCESS;
189 }
190
191 static void update_position( intf_thread_t *p_intf )
192 {
193     if( p_intf->p_sys->p_input )
194     {
195         hildon_seekbar_set_total_time( p_intf->p_sys->p_seekbar,
196                     var_GetTime( p_intf->p_sys->p_input, "length" )/1000000 );
197         hildon_seekbar_set_position( p_intf->p_sys->p_seekbar,
198                     var_GetTime( p_intf->p_sys->p_input, "time" )/1000000 );
199     }
200 }
201
202 static int interface_changed_cb( vlc_object_t *p_this, const char *psz_var,
203                                  vlc_value_t oldval, vlc_value_t newval,
204                                  void *param )
205 {
206     intf_thread_t *p_intf = (intf_thread_t *)param;
207     (void)p_this; (void)psz_var; (void)oldval; (void)newval;
208
209     vlc_spin_lock( &p_intf->p_sys->event_lock );
210     p_intf->p_sys->i_event |= EVENT_INTF_CHANGED;
211     vlc_spin_unlock( &p_intf->p_sys->event_lock );
212     g_idle_add( process_events, p_intf );
213     return VLC_SUCCESS;
214 }
215
216 static int input_event_cb( vlc_object_t *p_this, const char *psz_var,
217                            vlc_value_t oldval, vlc_value_t newval, void *param )
218 {
219     if( newval.i_int == INPUT_EVENT_STATE )
220         return item_changed_cb( p_this, psz_var, oldval, newval, param );
221     else
222         return interface_changed_cb( p_this, psz_var, oldval, newval, param );
223 }