1 /*****************************************************************************
2 * gnome_callbacks.c : Callbacks for the Gnome plugin.
3 *****************************************************************************
4 * Copyright (C) 2000, 2001 VideoLAN
6 * Authors: Samuel Hocevar <sam@zoy.org>
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.
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.
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 *****************************************************************************/
23 /*****************************************************************************
25 *****************************************************************************/
35 #include "stream_control.h"
36 #include "input_ext-intf.h"
38 #include "interface.h"
39 #include "intf_plst.h"
42 #include "gnome_sys.h"
43 #include "gnome_callbacks.h"
44 #include "gnome_interface.h"
45 #include "gnome_support.h"
49 /*****************************************************************************
50 * Inline function to retrieve the interface structure
51 *****************************************************************************/
52 static __inline__ intf_thread_t * GetIntf( GtkWidget *item, char * psz_parent )
54 return( gtk_object_get_data( GTK_OBJECT( lookup_widget(item, psz_parent) ),
58 /*****************************************************************************
60 ******************************************************************************/
62 on_menubar_open_activate (GtkMenuItem *menuitem,
65 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
67 /* If we have never used the file selector, open it */
68 if( p_intf->p_sys->p_fileopen == NULL)
70 p_intf->p_sys->p_fileopen = create_intf_fileopen();
71 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_fileopen ),
75 gtk_widget_show( p_intf->p_sys->p_fileopen );
76 gdk_window_raise( p_intf->p_sys->p_fileopen->window );
81 on_menubar_exit_activate (GtkMenuItem *menuitem,
84 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
91 on_menubar_playlist_activate (GtkMenuItem *menuitem,
94 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
96 if( !GTK_IS_WIDGET( p_intf->p_sys->p_playlist ) )
98 p_intf->p_sys->p_playlist = create_intf_playlist();
99 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_playlist ),
102 gtk_widget_show( p_intf->p_sys->p_playlist );
103 gdk_window_raise( p_intf->p_sys->p_playlist->window );
108 on_menubar_preferences_activate (GtkMenuItem *menuitem,
116 on_menubar_about_activate (GtkMenuItem *menuitem,
119 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
121 if( !GTK_IS_WIDGET( p_intf->p_sys->p_about ) )
123 p_intf->p_sys->p_about = create_intf_about();
124 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_about ),
127 gtk_widget_show( p_intf->p_sys->p_about );
128 gdk_window_raise( p_intf->p_sys->p_about->window );
133 on_toolbar_open_clicked (GtkButton *button,
136 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
138 /* If we have never used the file selector, open it */
139 if( p_intf->p_sys->p_fileopen == NULL)
141 p_intf->p_sys->p_fileopen = create_intf_fileopen();
142 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_fileopen ),
146 gtk_widget_show( p_intf->p_sys->p_fileopen );
147 gdk_window_raise( p_intf->p_sys->p_fileopen->window );
152 on_toolbar_back_clicked (GtkButton *button,
160 on_toolbar_stop_clicked (GtkButton *button,
168 on_toolbar_play_clicked (GtkButton *button,
171 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
173 if( p_intf->p_input != NULL )
175 input_SetStatus( p_intf->p_input, INPUT_STATUS_PLAY );
181 on_toolbar_pause_clicked (GtkButton *button,
184 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
186 if( p_intf->p_input != NULL )
188 input_SetStatus( p_intf->p_input, INPUT_STATUS_PAUSE );
194 on_toolbar_playlist_clicked (GtkButton *button,
197 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
199 if( !GTK_IS_WIDGET( p_intf->p_sys->p_playlist ) )
201 p_intf->p_sys->p_playlist = create_intf_playlist();
202 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_playlist ),
205 gtk_widget_show( p_intf->p_sys->p_playlist );
206 gdk_window_raise( p_intf->p_sys->p_playlist->window );
211 on_toolbar_prev_clicked (GtkButton *button,
214 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
216 if( p_intf->p_input != NULL )
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;
227 on_toolbar_next_clicked (GtkButton *button,
230 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
232 if( p_intf->p_input != NULL )
234 /* FIXME: temporary hack */
235 p_intf->p_input->b_eof = 1;
241 on_popup_play_activate (GtkMenuItem *menuitem,
244 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
246 if( p_intf->p_input != NULL )
248 input_SetStatus( p_intf->p_input, INPUT_STATUS_PLAY );
254 on_popup_pause_activate (GtkMenuItem *menuitem,
257 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
259 if( p_intf->p_input != NULL )
261 input_SetStatus( p_intf->p_input, INPUT_STATUS_PAUSE );
267 on_popup_exit_activate (GtkMenuItem *menuitem,
270 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
277 on_intf_window_destroy (GtkObject *object,
280 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(object), "intf_window" );
282 /* FIXME don't destroy the window, just hide it */
284 p_intf->p_sys->p_window = NULL;
289 on_fileopen_ok_clicked (GtkButton *button,
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));
299 intf_PlstAdd( p_main->p_playlist, PLAYLIST_END, (char*)filename );
304 on_fileopen_cancel_clicked (GtkButton *button,
307 gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
312 on_intf_fileopen_destroy (GtkObject *object,
315 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(object), "intf_fileopen" );
317 p_intf->p_sys->p_fileopen = NULL;
322 on_popup_open_activate (GtkMenuItem *menuitem,
325 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
327 /* If we have never used the file selector, open it */
328 if( p_intf->p_sys->p_fileopen == NULL)
330 p_intf->p_sys->p_fileopen = create_intf_fileopen();
331 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_fileopen ),
335 gtk_widget_show( p_intf->p_sys->p_fileopen );
336 gdk_window_raise( p_intf->p_sys->p_fileopen->window );
341 on_popup_about_activate (GtkMenuItem *menuitem,
344 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
346 if( !GTK_IS_WIDGET( p_intf->p_sys->p_about ) )
348 p_intf->p_sys->p_about = create_intf_about();
349 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_about ),
352 gtk_widget_show( p_intf->p_sys->p_about );
353 gdk_window_raise( p_intf->p_sys->p_about->window );
358 on_intf_playlist_destroy (GtkObject *object,
361 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(object), "intf_playlist" );
363 p_intf->p_sys->p_playlist = NULL;
368 on_playlist_close_clicked (GtkButton *button,
371 gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
376 on_popup_slow_activate (GtkMenuItem *menuitem,
379 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
381 if( p_intf->p_input != NULL )
383 input_SetStatus( p_intf->p_input, INPUT_STATUS_SLOWER );
389 on_popup_fast_activate (GtkMenuItem *menuitem,
392 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
394 if( p_intf->p_input != NULL )
396 input_SetStatus( p_intf->p_input, INPUT_STATUS_FASTER );
402 on_toolbar_slow_clicked (GtkButton *button,
405 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
407 if( p_intf->p_input != NULL )
409 input_SetStatus( p_intf->p_input, INPUT_STATUS_SLOWER );
415 on_toolbar_fast_clicked (GtkButton *button,
418 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
420 if( p_intf->p_input != NULL )
422 input_SetStatus( p_intf->p_input, INPUT_STATUS_FASTER );
428 on_hscale_button_release_event (GtkWidget *widget,
429 GdkEventButton *event,
432 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), "intf_window" );
434 GtkAdjustment *p_adj = gtk_range_get_adjustment( GTK_RANGE(widget) );
437 vlc_mutex_lock( &p_intf->p_sys->change_lock );
439 if( p_intf->p_input != NULL )
441 i_seek = (p_adj->value * p_intf->p_input->stream.i_size) / 100;
442 input_Seek( p_intf->p_input, i_seek );
444 p_intf->p_sys->b_scale_isfree = 1;
446 vlc_mutex_unlock( &p_intf->p_sys->change_lock );
453 on_hscale_button_press_event (GtkWidget *widget,
454 GdkEventButton *event,
457 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), "intf_window" );
459 vlc_mutex_lock( &p_intf->p_sys->change_lock );
460 p_intf->p_sys->b_scale_isfree = 0;
461 vlc_mutex_unlock( &p_intf->p_sys->change_lock );
469 on_intf_modules_destroy (GtkObject *object,
477 on_modules_ok_clicked (GtkButton *button,
480 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_modules" );
482 gtk_widget_hide( p_intf->p_sys->p_modules );
488 on_modules_apply_clicked (GtkButton *button,
496 on_modules_cancel_clicked (GtkButton *button,
499 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_modules" );
501 gtk_widget_hide( p_intf->p_sys->p_modules );
506 on_playlist_ok_clicked (GtkButton *button,
509 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_playlist" );
511 gtk_widget_hide( p_intf->p_sys->p_playlist );
516 on_menubar_modules_activate (GtkMenuItem *menuitem,
519 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
521 if( !GTK_IS_WIDGET( p_intf->p_sys->p_modules ) )
523 p_intf->p_sys->p_modules = create_intf_modules();
524 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_modules ),
527 gtk_widget_show( p_intf->p_sys->p_modules );
528 gdk_window_raise( p_intf->p_sys->p_modules->window );
533 on_intf_window_drag_data_received (GtkWidget *widget,
534 GdkDragContext *drag_context,
537 GtkSelectionData *data,
542 char *psz_text = data->data;
543 int i_len = strlen( psz_text );
547 case DROP_ACCEPT_TEXT_PLAIN: /* FIXME: handle multiple files */
554 /* get rid of ' ' at the end */
555 *( psz_text + i_len - 1 ) = 0;
557 intf_WarnMsg( 1, "intf: dropped text/uri-list data `%s'", psz_text );
558 intf_PlstAdd( p_main->p_playlist, PLAYLIST_END, psz_text );
562 case DROP_ACCEPT_TEXT_URI_LIST: /* FIXME: handle multiple files */
569 /* get rid of \r\n at the end */
570 *( psz_text + i_len - 2 ) = 0;
572 intf_WarnMsg( 1, "intf: dropped text/uri-list data `%s'", psz_text );
573 intf_PlstAdd( p_main->p_playlist, PLAYLIST_END, psz_text );
578 intf_ErrMsg( "intf error: unknown dropped type");