1 /*****************************************************************************
2 * gtk_open.c : functions to handle file/disc/network open widgets.
3 *****************************************************************************
4 * Copyright (C) 2000, 2001 VideoLAN
5 * $Id: gtk_open.c,v 1.20 2002/03/25 02:06:24 jobi Exp $
7 * Authors: Samuel Hocevar <sam@zoy.org>
8 * Stéphane Borel <stef@via.ecp.fr>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
23 *****************************************************************************/
25 /*****************************************************************************
27 *****************************************************************************/
28 #include <sys/types.h> /* off_t */
31 #include <videolan/vlc.h>
33 #ifdef MODULE_NAME_IS_gnome
41 #include "stream_control.h"
42 #include "input_ext-intf.h"
44 #include "interface.h"
45 #include "intf_playlist.h"
47 #include "gtk_callbacks.h"
48 #include "gtk_interface.h"
49 #include "gtk_support.h"
50 #include "gtk_playlist.h"
51 #include "gtk_common.h"
55 /*****************************************************************************
57 *****************************************************************************
58 * The following callbacks are related to the file requester.
59 *****************************************************************************/
60 gboolean GtkFileOpenShow( GtkWidget *widget,
61 GdkEventButton *event,
64 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), (char*)user_data );
66 /* If we have never used the file selector, open it */
67 if( !GTK_IS_WIDGET( p_intf->p_sys->p_fileopen ) )
71 p_intf->p_sys->p_fileopen = create_intf_fileopen();
72 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_fileopen ),
75 if( (psz_path = config_GetPszVariable( "search_path" )) )
76 gtk_file_selection_set_filename( GTK_FILE_SELECTION(
77 p_intf->p_sys->p_fileopen ), psz_path );
78 if( psz_path ) free( psz_path );
81 gtk_widget_show( p_intf->p_sys->p_fileopen );
82 gdk_window_raise( p_intf->p_sys->p_fileopen->window );
88 void GtkFileOpenCancel( GtkButton * button, gpointer user_data )
90 gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
93 void GtkFileOpenOk( GtkButton * button, gpointer user_data )
95 intf_thread_t * p_intf = GetIntf( GTK_WIDGET(button), "intf_fileopen" );
96 GtkCList * p_playlist_clist;
97 GtkWidget * p_filesel;
99 int i_end = p_main->p_playlist->i_size;
101 /* hide the file selector */
102 p_filesel = gtk_widget_get_toplevel( GTK_WIDGET(button) );
103 gtk_widget_hide( p_filesel );
105 /* add the new file to the interface playlist */
107 gtk_file_selection_get_filename( GTK_FILE_SELECTION( p_filesel ) );
108 intf_PlaylistAdd( p_main->p_playlist, PLAYLIST_END, (char*)psz_filename );
110 /* catch the GTK CList */
111 p_playlist_clist = GTK_CLIST( gtk_object_get_data(
112 GTK_OBJECT( p_intf->p_sys->p_playlist ), "playlist_clist" ) );
113 /* update the plugin display */
114 GtkRebuildCList( p_playlist_clist, p_main->p_playlist );
116 /* end current item, select added item */
117 if( p_input_bank->pp_input[0] != NULL )
119 p_input_bank->pp_input[0]->b_eof = 1;
122 intf_PlaylistJumpto( p_main->p_playlist, i_end - 1 );
125 /*****************************************************************************
126 * Open disc callbacks
127 *****************************************************************************
128 * The following callbacks are related to the disc manager.
129 *****************************************************************************/
130 gboolean GtkDiscOpenShow( GtkWidget *widget,
131 GdkEventButton *event,
134 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), (char*)user_data );
136 if( !GTK_IS_WIDGET( p_intf->p_sys->p_disc ) )
138 p_intf->p_sys->p_disc = create_intf_disc();
139 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_disc ),
143 gtk_widget_show( p_intf->p_sys->p_disc );
144 gdk_window_raise( p_intf->p_sys->p_disc->window );
150 void GtkDiscOpenDvd( GtkToggleButton * togglebutton, gpointer user_data )
152 if( togglebutton->active )
154 char *psz_dvd_device;
156 if( (psz_dvd_device = config_GetPszVariable( "dvd_device" )) )
158 GTK_ENTRY( lookup_widget( GTK_WIDGET(togglebutton),
159 "disc_name" ) ), psz_dvd_device );
160 if( psz_dvd_device ) free( psz_dvd_device );
164 void GtkDiscOpenVcd( GtkToggleButton * togglebutton, gpointer user_data )
166 if( togglebutton->active )
168 char *psz_vcd_device;
170 if( (psz_vcd_device = config_GetPszVariable( "vcd_device" )) )
172 GTK_ENTRY( lookup_widget( GTK_WIDGET(togglebutton),
173 "disc_name" ) ), psz_vcd_device );
174 if( psz_vcd_device ) free( psz_vcd_device );
178 void GtkDiscOpenOk( GtkButton * button, gpointer user_data )
180 intf_thread_t * p_intf = GetIntf( GTK_WIDGET(button), "intf_disc" );
181 GtkCList * p_playlist_clist;
182 char * psz_device, *psz_source, *psz_method;
183 int i_end = p_main->p_playlist->i_size;
184 int i_title, i_chapter;
186 gtk_widget_hide( p_intf->p_sys->p_disc );
187 psz_device = gtk_entry_get_text( GTK_ENTRY( lookup_widget(
188 GTK_WIDGET(button), "disc_name" ) ) );
190 /* Check which method was activated */
191 if( GTK_TOGGLE_BUTTON( lookup_widget( GTK_WIDGET(button),
192 "disc_dvd" ) )->active )
196 else if( GTK_TOGGLE_BUTTON( lookup_widget( GTK_WIDGET(button),
197 "disc_vcd" ) )->active )
203 intf_ErrMsg( "intf error: unknown disc type toggle button position" );
207 /* Select title and chapter */
208 i_title = gtk_spin_button_get_value_as_int(
209 GTK_SPIN_BUTTON( lookup_widget(
210 GTK_WIDGET(button), "disc_title" ) ) );
212 i_chapter = gtk_spin_button_get_value_as_int(
213 GTK_SPIN_BUTTON( lookup_widget(
214 GTK_WIDGET(button), "disc_chapter" ) ) );
216 /* "dvd:foo" has size 5 + strlen(foo) */
217 psz_source = malloc( 3 /* "dvd" */ + 1 /* ":" */
218 + strlen( psz_device ) + 2 /* @, */
219 + 4 /* i_title & i_chapter < 100 */ + 1 /* "\0" */ );
220 if( psz_source == NULL )
225 /* Build source name and add it to playlist */
226 sprintf( psz_source, "%s:%s@%d,%d",
227 psz_method, psz_device, i_title, i_chapter );
228 intf_PlaylistAdd( p_main->p_playlist, PLAYLIST_END, psz_source );
231 /* catch the GTK CList */
232 p_playlist_clist = GTK_CLIST( gtk_object_get_data(
233 GTK_OBJECT( p_intf->p_sys->p_playlist ), "playlist_clist" ) );
235 /* update the display */
236 GtkRebuildCList( p_playlist_clist, p_main->p_playlist );
238 /* stop current item, select added item */
239 if( p_input_bank->pp_input[0] != NULL )
241 p_input_bank->pp_input[0]->b_eof = 1;
244 intf_PlaylistJumpto( p_main->p_playlist, i_end - 1 );
248 void GtkDiscOpenCancel( GtkButton * button, gpointer user_data )
250 gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
254 /*****************************************************************************
255 * Network stream callbacks
256 *****************************************************************************
257 * The following callbacks are related to the network stream manager.
258 *****************************************************************************/
259 gboolean GtkNetworkOpenShow( GtkWidget *widget,
260 GdkEventButton *event,
263 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), (char*)user_data );
265 if( !GTK_IS_WIDGET( p_intf->p_sys->p_network ) )
267 char *psz_channel_server;
269 p_intf->p_sys->p_network = create_intf_network();
270 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_network ),
273 gtk_spin_button_set_value( GTK_SPIN_BUTTON( gtk_object_get_data(
274 GTK_OBJECT( p_intf->p_sys->p_network ), "network_port" ) ),
275 config_GetIntVariable( "server_port" ) );
277 psz_channel_server = config_GetPszVariable( "channel_server" );
278 if( psz_channel_server )
279 gtk_entry_set_text( GTK_ENTRY( gtk_object_get_data(
280 GTK_OBJECT( p_intf->p_sys->p_network ), "network_channel" ) ),
281 psz_channel_server );
282 if( psz_channel_server ) free( psz_channel_server );
284 gtk_spin_button_set_value( GTK_SPIN_BUTTON( gtk_object_get_data(
285 GTK_OBJECT( p_intf->p_sys->p_network ), "network_channel_port" ) ),
286 config_GetIntVariable( "channel_port" ) );
288 gtk_toggle_button_set_active( gtk_object_get_data( GTK_OBJECT(
289 p_intf->p_sys->p_network ), "network_channel_check" ),
290 config_GetIntVariable( "network_channel" ) );
293 gtk_widget_show( p_intf->p_sys->p_network );
294 gdk_window_raise( p_intf->p_sys->p_network->window );
300 void GtkNetworkOpenOk( GtkButton *button, gpointer user_data )
302 intf_thread_t * p_intf = GetIntf( GTK_WIDGET(button), "intf_network" );
303 GtkCList * p_playlist_clist;
304 char * psz_source, *psz_server, *psz_protocol;
306 boolean_t b_broadcast;
308 int i_end = p_main->p_playlist->i_size;
310 gtk_widget_hide( p_intf->p_sys->p_network );
311 psz_server = gtk_entry_get_text( GTK_ENTRY( lookup_widget(
312 GTK_WIDGET(button), "network_server" ) ) );
314 /* select added item */
315 if( p_input_bank->pp_input[0] != NULL )
317 p_input_bank->pp_input[0]->b_eof = 1;
320 /* Check which protocol was activated */
321 if( GTK_TOGGLE_BUTTON( lookup_widget( GTK_WIDGET(button),
322 "network_ts" ) )->active )
324 psz_protocol = "udpstream";
326 else if( GTK_TOGGLE_BUTTON( lookup_widget( GTK_WIDGET(button),
327 "network_rtp" ) )->active )
329 psz_protocol = "rtp";
333 intf_ErrMsg( "intf error: unknown protocol toggle button position" );
337 /* Manage channel server */
338 b_channel = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(
339 lookup_widget( GTK_WIDGET(button), "network_channel_check" ) ) );
340 config_PutIntVariable( "network_channel", b_channel );
344 unsigned int i_channel_port;
346 if( p_main->p_channel == NULL )
348 network_ChannelCreate();
351 psz_channel = gtk_entry_get_text( GTK_ENTRY( lookup_widget(
352 GTK_WIDGET(button), "network_channel" ) ) );
353 i_channel_port = gtk_spin_button_get_value_as_int( GTK_SPIN_BUTTON(
354 lookup_widget( GTK_WIDGET(button), "network_channel_port" ) ) );
356 config_PutPszVariable( "channel_server", psz_channel );
357 if( i_channel_port < 65536 )
359 config_PutIntVariable( "channel_port", i_channel_port );
362 p_intf->p_sys->b_playing = 1;
367 /* Get the port number and make sure it will not
368 * overflow 5 characters */
369 i_port = gtk_spin_button_get_value_as_int( GTK_SPIN_BUTTON(
370 lookup_widget( GTK_WIDGET(button), "network_port" ) ) );
373 intf_ErrMsg( "intf error: invalid port %i", i_port );
376 /* do we have a broadcast address */
377 b_broadcast = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(
378 lookup_widget( GTK_WIDGET(button), "network_broadcast_check" ) ) );
381 char * psz_broadcast;
382 psz_broadcast = gtk_entry_get_text( GTK_ENTRY( lookup_widget(
383 GTK_WIDGET(button), "network_broadcast" ) ) );
384 /* Allocate room for "protocol://server:port" */
385 psz_source = malloc( strlen( psz_protocol ) + 3 /* "://" */
386 + strlen( psz_server ) + 2 /* "@:" */
388 + strlen( psz_broadcast ) + 2 /* "::" */
390 if( psz_source == NULL )
395 /* Build source name and add it to playlist */
396 sprintf( psz_source, "%s://%s@:%i/%s", psz_protocol,
403 /* Allocate room for "protocol://server:port" */
404 psz_source = malloc( strlen( psz_protocol ) + 3 /* "://" */
405 + strlen( psz_server ) + 2 /* "@:" */
406 + 5 /* 0-65535 */ + 1 /* "\0" */ );
407 if( psz_source == NULL )
412 /* Build source name and add it to playlist */
413 sprintf( psz_source, "%s://%s@:%i",
414 psz_protocol, psz_server, i_port );
417 intf_PlaylistAdd( p_main->p_playlist, PLAYLIST_END, psz_source );
420 /* catch the GTK CList */
421 p_playlist_clist = GTK_CLIST( gtk_object_get_data(
422 GTK_OBJECT( p_intf->p_sys->p_playlist ), "playlist_clist" ) );
423 /* update the display */
424 GtkRebuildCList( p_playlist_clist, p_main->p_playlist );
426 intf_PlaylistJumpto( p_main->p_playlist, i_end - 1 );
430 void GtkNetworkOpenCancel( GtkButton * button, gpointer user_data)
432 gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
436 void GtkNetworkOpenBroadcast( GtkToggleButton * togglebutton,
439 GtkWidget * p_network;
441 p_network = gtk_widget_get_toplevel( GTK_WIDGET (togglebutton) );
443 gtk_widget_set_sensitive( gtk_object_get_data( GTK_OBJECT( p_network ),
444 "network_broadcast_combo" ),
445 gtk_toggle_button_get_active( togglebutton ) );
447 gtk_widget_set_sensitive( gtk_object_get_data( GTK_OBJECT( p_network ),
448 "network_broadcast" ),
449 gtk_toggle_button_get_active( togglebutton ) );
453 void GtkNetworkOpenChannel( GtkToggleButton * togglebutton,
456 GtkWidget * p_network;
458 boolean_t b_broadcast;
460 p_network = gtk_widget_get_toplevel( GTK_WIDGET (togglebutton) );
461 b_channel = gtk_toggle_button_get_active( togglebutton );
462 b_broadcast = gtk_toggle_button_get_active( gtk_object_get_data(
463 GTK_OBJECT( p_network ), "network_broadcast_check" ) );
465 gtk_widget_set_sensitive( gtk_object_get_data( GTK_OBJECT( p_network ),
466 "network_channel_combo" ), b_channel ) ;
468 gtk_widget_set_sensitive( gtk_object_get_data( GTK_OBJECT( p_network ),
469 "network_channel" ), b_channel );
471 gtk_widget_set_sensitive( gtk_object_get_data( GTK_OBJECT( p_network ),
472 "network_channel_port" ), b_channel );
474 gtk_widget_set_sensitive( gtk_object_get_data( GTK_OBJECT( p_network ),
475 "network_channel_port_label" ), b_channel );
477 gtk_widget_set_sensitive( gtk_object_get_data( GTK_OBJECT( p_network ),
478 "network_server_combo" ), ! b_channel );
480 gtk_widget_set_sensitive( gtk_object_get_data( GTK_OBJECT( p_network ),
481 "network_server_label" ), ! b_channel );
483 gtk_widget_set_sensitive( gtk_object_get_data( GTK_OBJECT( p_network ),
484 "network_server" ), ! b_channel );
486 gtk_widget_set_sensitive( gtk_object_get_data( GTK_OBJECT( p_network ),
487 "network_port_label" ), ! b_channel );
489 gtk_widget_set_sensitive( gtk_object_get_data( GTK_OBJECT( p_network ),
490 "network_port" ), ! b_channel );
492 gtk_widget_set_sensitive( gtk_object_get_data( GTK_OBJECT( p_network ),
493 "network_broadcast_check" ), ! b_channel );
495 gtk_widget_set_sensitive( gtk_object_get_data( GTK_OBJECT( p_network ),
496 "network_broadcast_combo" ), b_broadcast && ! b_channel );
498 gtk_widget_set_sensitive( gtk_object_get_data( GTK_OBJECT( p_network ),
499 "network_broadcast" ), b_broadcast && ! b_channel );
502 /*****************************************************************************
503 * Open satellite callbacks
504 *****************************************************************************
505 * The following callbacks are related to the satellite card manager.
506 *****************************************************************************/
507 gboolean GtkSatOpenShow( GtkWidget *widget,
508 GdkEventButton *event,
511 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), (char*)user_data );
513 if( !GTK_IS_WIDGET( p_intf->p_sys->p_sat ) )
515 p_intf->p_sys->p_sat = create_intf_sat();
516 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_sat ),
520 gtk_widget_show( p_intf->p_sys->p_sat );
521 gdk_window_raise( p_intf->p_sys->p_sat->window );
526 void GtkSatOpenOk( GtkButton * button, gpointer user_data )
528 intf_thread_t * p_intf = GetIntf( GTK_WIDGET(button), "intf_sat" );
529 GtkCList * p_playlist_clist;
531 int i_end = p_main->p_playlist->i_size;
535 gtk_widget_hide( p_intf->p_sys->p_sat );
537 /* Check which polarization was activated */
538 if( GTK_TOGGLE_BUTTON( lookup_widget( GTK_WIDGET(button),
539 "sat_pol_vert" ) )->active )
548 /* Select frequency and symbol rate */
549 i_freq = gtk_spin_button_get_value_as_int(
550 GTK_SPIN_BUTTON( lookup_widget(
551 GTK_WIDGET(button), "sat_freq" ) ) );
553 i_srate = gtk_spin_button_get_value_as_int(
554 GTK_SPIN_BUTTON( lookup_widget(
555 GTK_WIDGET(button), "sat_srate" ) ) );
557 psz_source = malloc( 22 );
558 if( psz_source == NULL )
563 /* Build source name and add it to playlist */
564 sprintf( psz_source, "%s:%d,%d,%d",
565 "satellite", i_freq, b_pol, i_srate );
566 intf_PlaylistAdd( p_main->p_playlist, PLAYLIST_END, psz_source );
569 /* catch the GTK CList */
570 p_playlist_clist = GTK_CLIST( gtk_object_get_data(
571 GTK_OBJECT( p_intf->p_sys->p_playlist ), "playlist_clist" ) );
573 /* update the display */
574 GtkRebuildCList( p_playlist_clist, p_main->p_playlist );
576 /* stop current item, select added item */
577 if( p_input_bank->pp_input[0] != NULL )
579 p_input_bank->pp_input[0]->b_eof = 1;
582 intf_PlaylistJumpto( p_main->p_playlist, i_end - 1 );
586 void GtkSatOpenCancel( GtkButton * button, gpointer user_data )
588 gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
591 /****************************************************************************
592 * Callbacks for menuitem
593 ****************************************************************************/
594 void GtkFileOpenActivate( GtkMenuItem * menuitem, gpointer user_data )
596 GtkFileOpenShow( GTK_WIDGET( menuitem ), NULL, user_data );
600 void GtkDiscOpenActivate( GtkMenuItem * menuitem, gpointer user_data )
602 GtkDiscOpenShow( GTK_WIDGET( menuitem ), NULL, user_data );
606 void GtkNetworkOpenActivate( GtkMenuItem * menuitem, gpointer user_data )
608 GtkNetworkOpenShow( GTK_WIDGET( menuitem ), NULL, user_data );