]> git.sesse.net Git - vlc/blob - plugins/gnome/gnome_callbacks.c
* Fixed my old stupid bug that disabled sound after having played the
[vlc] / plugins / gnome / gnome_callbacks.c
1 /*****************************************************************************
2  * gnome_callbacks.c : Callbacks for the Gnome plugin.
3  *****************************************************************************
4  * Copyright (C) 2000, 2001 VideoLAN
5  *
6  * Authors: Samuel Hocevar <sam@zoy.org>
7  *      
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  * 
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
21  *****************************************************************************/
22
23 /*****************************************************************************
24  * Preamble
25  *****************************************************************************/
26 #include "defs.h"
27
28 #include <gnome.h>
29
30 #include "config.h"
31 #include "common.h"
32 #include "threads.h"
33 #include "mtime.h"
34
35 #include "stream_control.h"
36 #include "input_ext-intf.h"
37
38 #include "interface.h"
39 #include "intf_plst.h"
40
41 #include "gnome_sys.h"
42 #include "gnome_callbacks.h"
43 #include "gnome_interface.h"
44 #include "gnome_support.h"
45
46 #include "main.h"
47
48 /*****************************************************************************
49  * Inline function to retrieve the interface structure
50  *****************************************************************************/
51 static __inline__ intf_thread_t * GetIntf( GtkWidget *item, char * psz_parent )
52 {
53     return( gtk_object_get_data( GTK_OBJECT( lookup_widget(item, psz_parent) ),
54                                  "p_intf" ) );
55 }
56
57 /*****************************************************************************
58  * Callbacks
59  ******************************************************************************/
60 void
61 on_menubar_open_activate               (GtkMenuItem     *menuitem,
62                                         gpointer         user_data)
63 {
64     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
65
66     /* If we have never used the file selector, open it */
67     if( p_intf->p_sys->p_fileopen == NULL)
68     {
69         p_intf->p_sys->p_fileopen = create_intf_fileopen();
70         gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_fileopen ),
71                              "p_intf", p_intf );
72     }
73
74     gtk_widget_show( p_intf->p_sys->p_fileopen );
75     gdk_window_raise( p_intf->p_sys->p_fileopen->window );
76 }
77
78
79 void
80 on_menubar_exit_activate               (GtkMenuItem     *menuitem,
81                                         gpointer         user_data)
82 {
83     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
84
85     p_intf->b_die = 1;
86 }
87
88
89 void
90 on_menubar_playlist_activate           (GtkMenuItem     *menuitem,
91                                         gpointer         user_data)
92 {
93     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
94
95     if( !GTK_IS_WIDGET( p_intf->p_sys->p_playlist ) )
96     {
97         p_intf->p_sys->p_playlist = create_intf_playlist();
98         gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_playlist ),
99                              "p_intf", p_intf );
100     }
101     gtk_widget_show( p_intf->p_sys->p_playlist );
102 }
103
104
105 void
106 on_menubar_plugins_activate            (GtkMenuItem     *menuitem,
107                                         gpointer         user_data)
108 {
109
110 }
111
112
113 void
114 on_menubar_preferences_activate        (GtkMenuItem     *menuitem,
115                                         gpointer         user_data)
116 {
117
118 }
119
120
121 void
122 on_menubar_about_activate              (GtkMenuItem     *menuitem,
123                                         gpointer         user_data)
124 {
125     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
126
127     if( !GTK_IS_WIDGET( p_intf->p_sys->p_about ) )
128     {
129         p_intf->p_sys->p_about = create_intf_about();
130         gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_about ),
131                              "p_intf", p_intf );
132     }
133     gtk_widget_show( p_intf->p_sys->p_about );
134 }
135
136
137 void
138 on_toolbar_open_clicked                (GtkButton       *button,
139                                         gpointer         user_data)
140 {
141     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
142
143     /* If we have never used the file selector, open it */
144     if( p_intf->p_sys->p_fileopen == NULL)
145     {
146         p_intf->p_sys->p_fileopen = create_intf_fileopen();
147         gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_fileopen ),
148                              "p_intf", p_intf );
149     }
150
151     gtk_widget_show( p_intf->p_sys->p_fileopen );
152     gdk_window_raise( p_intf->p_sys->p_fileopen->window );
153 }
154
155
156 void
157 on_toolbar_back_clicked                (GtkButton       *button,
158                                         gpointer         user_data)
159 {
160
161 }
162
163
164 void
165 on_toolbar_stop_clicked                (GtkButton       *button,
166                                         gpointer         user_data)
167 {
168
169 }
170
171
172 void
173 on_toolbar_play_clicked                (GtkButton       *button,
174                                         gpointer         user_data)
175 {
176     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
177
178     if( p_intf->p_input != NULL )
179     {
180         input_Play( p_intf->p_input );
181     }
182 }
183
184
185 void
186 on_toolbar_pause_clicked               (GtkButton       *button,
187                                         gpointer         user_data)
188 {
189     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
190
191     if( p_intf->p_input != NULL )
192     {
193         input_Pause( p_intf->p_input );
194     }
195 }
196
197
198 void
199 on_toolbar_playlist_clicked            (GtkButton       *button,
200                                         gpointer         user_data)
201 {
202     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
203
204     if( !GTK_IS_WIDGET( p_intf->p_sys->p_playlist ) )
205     {
206         p_intf->p_sys->p_playlist = create_intf_playlist();
207         gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_playlist ),
208                              "p_intf", p_intf );
209     }
210     gtk_widget_show( p_intf->p_sys->p_playlist );
211 }
212
213
214 void
215 on_toolbar_prev_clicked                (GtkButton       *button,
216                                         gpointer         user_data)
217 {
218     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
219
220     if( p_intf->p_input != NULL )
221     {
222         /* FIXME: temporary hack */
223         intf_PlstPrev( p_main->p_playlist );
224         intf_PlstPrev( p_main->p_playlist );
225         p_intf->p_input->b_eof = 1;
226     }
227 }
228
229
230 void
231 on_toolbar_next_clicked                (GtkButton       *button,
232                                         gpointer         user_data)
233 {
234     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
235
236     if( p_intf->p_input != NULL )
237     {
238         /* FIXME: temporary hack */
239         p_intf->p_input->b_eof = 1;
240     }
241 }
242
243
244 void
245 on_popup_play_activate                 (GtkMenuItem     *menuitem,
246                                         gpointer         user_data)
247 {
248     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
249
250     if( p_intf->p_input != NULL )
251     {
252         input_Play( p_intf->p_input );
253     }
254 }
255
256
257 void
258 on_popup_pause_activate                (GtkMenuItem     *menuitem,
259                                         gpointer         user_data)
260 {
261     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
262
263     if( p_intf->p_input != NULL )
264     {
265         input_Pause( p_intf->p_input );
266     }
267 }
268
269
270 void
271 on_popup_exit_activate                 (GtkMenuItem     *menuitem,
272                                         gpointer         user_data)
273 {
274     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
275
276     p_intf->b_die = 1;
277 }
278
279
280 void
281 on_intf_window_destroy                 (GtkObject       *object,
282                                         gpointer         user_data)
283 {
284     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(object), "intf_window" );
285
286     /* FIXME don't destroy the window, just hide it */
287     p_intf->b_die = 1;
288     p_intf->p_sys->p_window = NULL;
289 }
290
291
292 void
293 on_fileopen_ok_clicked                 (GtkButton       *button,
294                                         gpointer         user_data)
295 {
296     GtkWidget *filesel;
297     gchar *filename;
298
299     filesel = gtk_widget_get_toplevel (GTK_WIDGET (button));
300     gtk_widget_hide (filesel);
301     filename = gtk_file_selection_get_filename (GTK_FILE_SELECTION (filesel));
302
303     intf_PlstAdd( p_main->p_playlist, PLAYLIST_END, (char*)filename );
304 }
305
306
307 void
308 on_fileopen_cancel_clicked             (GtkButton       *button,
309                                         gpointer         user_data)
310 {
311     gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
312 }
313
314
315 void
316 on_intf_fileopen_destroy               (GtkObject       *object,
317                                         gpointer         user_data)
318 {
319     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(object), "intf_fileopen" );
320
321     p_intf->p_sys->p_fileopen = NULL;
322 }
323
324
325 void
326 on_popup_open_activate                 (GtkMenuItem     *menuitem,
327                                         gpointer         user_data)
328 {
329     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
330
331     /* If we have never used the file selector, open it */
332     if( p_intf->p_sys->p_fileopen == NULL)
333     {
334         p_intf->p_sys->p_fileopen = create_intf_fileopen();
335         gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_fileopen ),
336                              "p_intf", p_intf );
337     }
338
339     gtk_widget_show( p_intf->p_sys->p_fileopen );
340     gdk_window_raise( p_intf->p_sys->p_fileopen->window );
341 }
342
343
344 void
345 on_popup_about_activate                (GtkMenuItem     *menuitem,
346                                         gpointer         user_data)
347 {
348     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
349
350     if( !GTK_IS_WIDGET( p_intf->p_sys->p_about ) )
351     {
352         p_intf->p_sys->p_about = create_intf_about();
353         gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_about ),
354                              "p_intf", p_intf );
355     }
356     gtk_widget_show( p_intf->p_sys->p_about );
357 }
358
359
360 void
361 on_intf_playlist_destroy               (GtkObject       *object,
362                                         gpointer         user_data)
363 {
364     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(object), "intf_playlist" );
365
366     p_intf->p_sys->p_playlist = NULL;
367 }
368
369
370 void
371 on_playlist_close_clicked              (GtkButton       *button,
372                                         gpointer         user_data)
373 {
374     gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
375 }
376
377
378 void
379 on_popup_slow_activate                 (GtkMenuItem     *menuitem,
380                                         gpointer         user_data)
381 {
382     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
383     int i_rate;
384
385     if( p_intf->p_input != NULL )
386     {
387         i_rate = p_intf->p_input->stream.control.i_rate * 2;
388         if ( i_rate <= MAXIMAL_RATE )
389         {
390              if ( i_rate > 500 && i_rate < 1000 )
391                  i_rate = 1000;
392
393              input_Forward( p_intf->p_input, i_rate );
394         }
395     }
396 }
397
398
399 void
400 on_popup_fast_activate                 (GtkMenuItem     *menuitem,
401                                         gpointer         user_data)
402 {
403     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
404     int i_rate;
405
406     if( p_intf->p_input != NULL )
407     {
408         i_rate = p_intf->p_input->stream.control.i_rate / 2;
409         if ( i_rate >= MINIMAL_RATE )
410         {
411              input_Forward( p_intf->p_input, i_rate );
412         }
413     }
414 }
415
416
417 void
418 on_toolbar_slow_clicked                (GtkButton       *button,
419                                         gpointer         user_data)
420 {
421     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
422     int i_rate;
423
424     if( p_intf->p_input != NULL )
425     {
426         i_rate = p_intf->p_input->stream.control.i_rate * 2;
427         if ( i_rate <= MAXIMAL_RATE )
428         {
429              if ( i_rate > 500 && i_rate < 1000 )
430                  i_rate = 1000;
431
432              input_Forward( p_intf->p_input, i_rate );
433         }
434     }
435 }
436
437
438 void
439 on_toolbar_fast_clicked                (GtkButton       *button,
440                                         gpointer         user_data)
441 {
442     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
443     int i_rate;
444
445     if( p_intf->p_input != NULL )
446     {
447         i_rate = p_intf->p_input->stream.control.i_rate / 2;
448         if ( i_rate >= MINIMAL_RATE )
449         {
450              input_Forward( p_intf->p_input, i_rate );
451         }
452     }
453 }
454