]> git.sesse.net Git - vlc/blob - plugins/gnome/gnome_callbacks.c
Removed flooding debug info :)
[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 #include "intf_msg.h"
41
42 #include "gnome_sys.h"
43 #include "gnome_callbacks.h"
44 #include "gnome_interface.h"
45 #include "gnome_support.h"
46
47 #include "main.h"
48
49 /*****************************************************************************
50  * Inline function to retrieve the interface structure
51  *****************************************************************************/
52 static __inline__ intf_thread_t * GetIntf( GtkWidget *item, char * psz_parent )
53 {
54     return( gtk_object_get_data( GTK_OBJECT( lookup_widget(item, psz_parent) ),
55                                  "p_intf" ) );
56 }
57
58 /*****************************************************************************
59  * Callbacks
60  ******************************************************************************/
61 void
62 on_menubar_open_activate               (GtkMenuItem     *menuitem,
63                                         gpointer         user_data)
64 {
65     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
66
67     /* If we have never used the file selector, open it */
68     if( p_intf->p_sys->p_fileopen == NULL)
69     {
70         p_intf->p_sys->p_fileopen = create_intf_fileopen();
71         gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_fileopen ),
72                              "p_intf", p_intf );
73     }
74
75     gtk_widget_show( p_intf->p_sys->p_fileopen );
76     gdk_window_raise( p_intf->p_sys->p_fileopen->window );
77 }
78
79
80 void
81 on_menubar_exit_activate               (GtkMenuItem     *menuitem,
82                                         gpointer         user_data)
83 {
84     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
85
86     p_intf->b_die = 1;
87 }
88
89
90 void
91 on_menubar_playlist_activate           (GtkMenuItem     *menuitem,
92                                         gpointer         user_data)
93 {
94     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
95
96     if( !GTK_IS_WIDGET( p_intf->p_sys->p_playlist ) )
97     {
98         p_intf->p_sys->p_playlist = create_intf_playlist();
99         gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_playlist ),
100                              "p_intf", p_intf );
101     }
102     gtk_widget_show( p_intf->p_sys->p_playlist );
103     gdk_window_raise( p_intf->p_sys->p_playlist->window );
104 }
105
106
107 void
108 on_menubar_preferences_activate        (GtkMenuItem     *menuitem,
109                                         gpointer         user_data)
110 {
111
112 }
113
114
115 void
116 on_menubar_about_activate              (GtkMenuItem     *menuitem,
117                                         gpointer         user_data)
118 {
119     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
120
121     if( !GTK_IS_WIDGET( p_intf->p_sys->p_about ) )
122     {
123         p_intf->p_sys->p_about = create_intf_about();
124         gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_about ),
125                              "p_intf", p_intf );
126     }
127     gtk_widget_show( p_intf->p_sys->p_about );
128     gdk_window_raise( p_intf->p_sys->p_about->window );
129 }
130
131
132 void
133 on_toolbar_open_clicked                (GtkButton       *button,
134                                         gpointer         user_data)
135 {
136     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
137
138     /* If we have never used the file selector, open it */
139     if( p_intf->p_sys->p_fileopen == NULL)
140     {
141         p_intf->p_sys->p_fileopen = create_intf_fileopen();
142         gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_fileopen ),
143                              "p_intf", p_intf );
144     }
145
146     gtk_widget_show( p_intf->p_sys->p_fileopen );
147     gdk_window_raise( p_intf->p_sys->p_fileopen->window );
148 }
149
150
151 void
152 on_toolbar_back_clicked                (GtkButton       *button,
153                                         gpointer         user_data)
154 {
155
156 }
157
158
159 void
160 on_toolbar_stop_clicked                (GtkButton       *button,
161                                         gpointer         user_data)
162 {
163
164 }
165
166
167 void
168 on_toolbar_play_clicked                (GtkButton       *button,
169                                         gpointer         user_data)
170 {
171     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
172
173     if( p_intf->p_input != NULL )
174     {
175         input_SetStatus( p_intf->p_input, INPUT_STATUS_PLAY );
176     }
177 }
178
179
180 void
181 on_toolbar_pause_clicked               (GtkButton       *button,
182                                         gpointer         user_data)
183 {
184     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
185
186     if( p_intf->p_input != NULL )
187     {
188         input_SetStatus( p_intf->p_input, INPUT_STATUS_PAUSE );
189     }
190 }
191
192
193 void
194 on_toolbar_playlist_clicked            (GtkButton       *button,
195                                         gpointer         user_data)
196 {
197     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
198
199     if( !GTK_IS_WIDGET( p_intf->p_sys->p_playlist ) )
200     {
201         p_intf->p_sys->p_playlist = create_intf_playlist();
202         gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_playlist ),
203                              "p_intf", p_intf );
204     }
205     gtk_widget_show( p_intf->p_sys->p_playlist );
206     gdk_window_raise( p_intf->p_sys->p_playlist->window );
207 }
208
209
210 void
211 on_toolbar_prev_clicked                (GtkButton       *button,
212                                         gpointer         user_data)
213 {
214     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
215
216     if( p_intf->p_input != NULL )
217     {
218         /* FIXME: temporary hack */
219         intf_PlstPrev( p_main->p_playlist );
220         intf_PlstPrev( p_main->p_playlist );
221         p_intf->p_input->b_eof = 1;
222     }
223 }
224
225
226 void
227 on_toolbar_next_clicked                (GtkButton       *button,
228                                         gpointer         user_data)
229 {
230     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
231
232     if( p_intf->p_input != NULL )
233     {
234         /* FIXME: temporary hack */
235         p_intf->p_input->b_eof = 1;
236     }
237 }
238
239
240 void
241 on_popup_play_activate                 (GtkMenuItem     *menuitem,
242                                         gpointer         user_data)
243 {
244     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
245
246     if( p_intf->p_input != NULL )
247     {
248         input_SetStatus( p_intf->p_input, INPUT_STATUS_PLAY );
249     }
250 }
251
252
253 void
254 on_popup_pause_activate                (GtkMenuItem     *menuitem,
255                                         gpointer         user_data)
256 {
257     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
258
259     if( p_intf->p_input != NULL )
260     {
261         input_SetStatus( p_intf->p_input, INPUT_STATUS_PAUSE );
262     }
263 }
264
265
266 void
267 on_popup_exit_activate                 (GtkMenuItem     *menuitem,
268                                         gpointer         user_data)
269 {
270     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
271
272     p_intf->b_die = 1;
273 }
274
275
276 void
277 on_intf_window_destroy                 (GtkObject       *object,
278                                         gpointer         user_data)
279 {
280     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(object), "intf_window" );
281
282     /* FIXME don't destroy the window, just hide it */
283     p_intf->b_die = 1;
284     p_intf->p_sys->p_window = NULL;
285 }
286
287
288 void
289 on_fileopen_ok_clicked                 (GtkButton       *button,
290                                         gpointer         user_data)
291 {
292     GtkWidget *filesel;
293     gchar *filename;
294
295     filesel = gtk_widget_get_toplevel (GTK_WIDGET (button));
296     gtk_widget_hide (filesel);
297     filename = gtk_file_selection_get_filename (GTK_FILE_SELECTION (filesel));
298
299     intf_PlstAdd( p_main->p_playlist, PLAYLIST_END, (char*)filename );
300 }
301
302
303 void
304 on_fileopen_cancel_clicked             (GtkButton       *button,
305                                         gpointer         user_data)
306 {
307     gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
308 }
309
310
311 void
312 on_intf_fileopen_destroy               (GtkObject       *object,
313                                         gpointer         user_data)
314 {
315     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(object), "intf_fileopen" );
316
317     p_intf->p_sys->p_fileopen = NULL;
318 }
319
320
321 void
322 on_popup_open_activate                 (GtkMenuItem     *menuitem,
323                                         gpointer         user_data)
324 {
325     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
326
327     /* If we have never used the file selector, open it */
328     if( p_intf->p_sys->p_fileopen == NULL)
329     {
330         p_intf->p_sys->p_fileopen = create_intf_fileopen();
331         gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_fileopen ),
332                              "p_intf", p_intf );
333     }
334
335     gtk_widget_show( p_intf->p_sys->p_fileopen );
336     gdk_window_raise( p_intf->p_sys->p_fileopen->window );
337 }
338
339
340 void
341 on_popup_about_activate                (GtkMenuItem     *menuitem,
342                                         gpointer         user_data)
343 {
344     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
345
346     if( !GTK_IS_WIDGET( p_intf->p_sys->p_about ) )
347     {
348         p_intf->p_sys->p_about = create_intf_about();
349         gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_about ),
350                              "p_intf", p_intf );
351     }
352     gtk_widget_show( p_intf->p_sys->p_about );
353     gdk_window_raise( p_intf->p_sys->p_about->window );
354 }
355
356
357 void
358 on_intf_playlist_destroy               (GtkObject       *object,
359                                         gpointer         user_data)
360 {
361     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(object), "intf_playlist" );
362
363     p_intf->p_sys->p_playlist = NULL;
364 }
365
366
367 void
368 on_playlist_close_clicked              (GtkButton       *button,
369                                         gpointer         user_data)
370 {
371     gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
372 }
373
374
375 void
376 on_popup_slow_activate                 (GtkMenuItem     *menuitem,
377                                         gpointer         user_data)
378 {
379     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
380
381     if( p_intf->p_input != NULL )
382     {
383         input_SetStatus( p_intf->p_input, INPUT_STATUS_SLOWER );
384     }
385 }
386
387
388 void
389 on_popup_fast_activate                 (GtkMenuItem     *menuitem,
390                                         gpointer         user_data)
391 {
392     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
393
394     if( p_intf->p_input != NULL )
395     {
396         input_SetStatus( p_intf->p_input, INPUT_STATUS_FASTER );
397     }
398 }
399
400
401 void
402 on_toolbar_slow_clicked                (GtkButton       *button,
403                                         gpointer         user_data)
404 {
405     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
406
407     if( p_intf->p_input != NULL )
408     {
409         input_SetStatus( p_intf->p_input, INPUT_STATUS_SLOWER );
410     }
411 }
412
413
414 void
415 on_toolbar_fast_clicked                (GtkButton       *button,
416                                         gpointer         user_data)
417 {
418     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
419
420     if( p_intf->p_input != NULL )
421     {
422         input_SetStatus( p_intf->p_input, INPUT_STATUS_FASTER );
423     }
424 }
425
426
427 gboolean
428 on_hscale_button_release_event         (GtkWidget       *widget,
429                                         GdkEventButton  *event,
430                                         gpointer         user_data)
431 {
432     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), "intf_window" );
433
434     GtkAdjustment *p_adj = gtk_range_get_adjustment( GTK_RANGE(widget) );
435     off_t i_seek;
436
437     vlc_mutex_lock( &p_intf->p_sys->change_lock );
438
439     if( p_intf->p_input != NULL )
440     {
441         i_seek = (p_adj->value *
442                   p_intf->p_input->stream.pp_areas[0]->i_size) / 100;
443         input_Seek( p_intf->p_input, i_seek );
444     }
445     p_intf->p_sys->b_scale_isfree = 1;
446
447     vlc_mutex_unlock( &p_intf->p_sys->change_lock );
448
449     return FALSE;
450 }
451
452
453 gboolean
454 on_hscale_button_press_event           (GtkWidget       *widget,
455                                         GdkEventButton  *event,
456                                         gpointer         user_data)
457 {
458     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), "intf_window" );
459
460     vlc_mutex_lock( &p_intf->p_sys->change_lock );
461     p_intf->p_sys->b_scale_isfree = 0;
462     vlc_mutex_unlock( &p_intf->p_sys->change_lock );
463
464     return FALSE;
465 }
466
467
468
469 void
470 on_intf_modules_destroy                (GtkObject       *object,
471                                         gpointer         user_data)
472 {
473
474 }
475
476
477 void
478 on_modules_ok_clicked                  (GtkButton       *button,
479                                         gpointer         user_data)
480 {
481     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_modules" );
482
483     gtk_widget_hide( p_intf->p_sys->p_modules );
484
485 }
486
487
488 void
489 on_modules_apply_clicked               (GtkButton       *button,
490                                         gpointer         user_data)
491 {
492
493 }
494
495
496 void
497 on_modules_cancel_clicked              (GtkButton       *button,
498                                         gpointer         user_data)
499 {
500     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_modules" );
501
502     gtk_widget_hide( p_intf->p_sys->p_modules );
503 }
504
505
506 void
507 on_playlist_ok_clicked                 (GtkButton       *button,
508                                         gpointer         user_data)
509 {
510     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_playlist" );
511
512     gtk_widget_hide( p_intf->p_sys->p_playlist );
513 }
514
515
516 void
517 on_menubar_modules_activate            (GtkMenuItem     *menuitem,
518                                         gpointer         user_data)
519 {
520     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
521
522     if( !GTK_IS_WIDGET( p_intf->p_sys->p_modules ) )
523     {
524         p_intf->p_sys->p_modules = create_intf_modules();
525         gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_modules ),
526                              "p_intf", p_intf );
527     }
528     gtk_widget_show( p_intf->p_sys->p_modules );
529     gdk_window_raise( p_intf->p_sys->p_modules->window );
530 }
531
532
533 void
534 on_intf_window_drag_data_received      (GtkWidget       *widget,
535                                         GdkDragContext  *drag_context,
536                                         gint             x,
537                                         gint             y,
538                                         GtkSelectionData *data,
539                                         guint            info,
540                                         guint            time,
541                                         gpointer         user_data)
542 {
543     char *psz_text = data->data;
544     int i_len      = strlen( psz_text );
545
546     switch( info )
547     {
548     case DROP_ACCEPT_TEXT_PLAIN: /* FIXME: handle multiple files */
549
550         if( i_len < 1 )
551         {
552             return;
553         }
554
555         /* get rid of ' ' at the end */
556         *( psz_text + i_len - 1 ) = 0;
557
558         intf_WarnMsg( 1, "intf: dropped text/uri-list data `%s'", psz_text );
559         intf_PlstAdd( p_main->p_playlist, PLAYLIST_END, psz_text );
560
561         break;
562
563     case DROP_ACCEPT_TEXT_URI_LIST: /* FIXME: handle multiple files */
564
565         if( i_len < 2 )
566         {
567             return;
568         }
569
570         /* get rid of \r\n at the end */
571         *( psz_text + i_len - 2 ) = 0;
572
573         intf_WarnMsg( 1, "intf: dropped text/uri-list data `%s'", psz_text );
574         intf_PlstAdd( p_main->p_playlist, PLAYLIST_END, psz_text );
575         break;
576
577     default:
578
579         intf_ErrMsg( "intf error: unknown dropped type");
580         break;
581     }
582 }
583