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.9 2001/11/28 15:08:05 massiot 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 *****************************************************************************/
29 #include <sys/types.h> /* off_t */
34 #if ( MODULE_NAME == gtk )
36 #elif ( MODULE_NAME == gnome )
50 #include "stream_control.h"
51 #include "input_ext-intf.h"
53 #include "interface.h"
54 #include "intf_playlist.h"
56 #include "gtk_callbacks.h"
57 #include "gtk_interface.h"
58 #include "gtk_support.h"
59 #include "gtk_playlist.h"
65 #include "modules_export.h"
67 /*****************************************************************************
69 *****************************************************************************
70 * The following callbacks are related to the file requester.
71 *****************************************************************************/
72 gboolean GtkFileOpenShow( GtkWidget *widget,
73 GdkEventButton *event,
76 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), (char*)user_data );
78 /* If we have never used the file selector, open it */
79 if( !GTK_IS_WIDGET( p_intf->p_sys->p_fileopen ) )
81 p_intf->p_sys->p_fileopen = create_intf_fileopen();
82 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_fileopen ),
85 gtk_file_selection_set_filename( GTK_FILE_SELECTION(
86 p_intf->p_sys->p_fileopen ),
87 main_GetPszVariable( INTF_PATH_VAR, INTF_PATH_DEFAULT ) );
90 gtk_widget_show( p_intf->p_sys->p_fileopen );
91 gdk_window_raise( p_intf->p_sys->p_fileopen->window );
97 void GtkFileOpenCancel( GtkButton * button, gpointer user_data )
99 gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
102 void GtkFileOpenOk( GtkButton * button, gpointer user_data )
104 intf_thread_t * p_intf = GetIntf( GTK_WIDGET(button), "intf_fileopen" );
105 GtkCList * p_playlist_clist;
106 GtkWidget * p_filesel;
107 gchar * psz_filename;
108 int i_end = p_main->p_playlist->i_size;
110 /* hide the file selector */
111 p_filesel = gtk_widget_get_toplevel( GTK_WIDGET(button) );
112 gtk_widget_hide( p_filesel );
114 /* add the new file to the interface playlist */
116 gtk_file_selection_get_filename( GTK_FILE_SELECTION( p_filesel ) );
117 intf_PlaylistAdd( p_main->p_playlist, PLAYLIST_END, (char*)psz_filename );
119 /* catch the GTK CList */
120 p_playlist_clist = GTK_CLIST( gtk_object_get_data(
121 GTK_OBJECT( p_intf->p_sys->p_playlist ), "playlist_clist" ) );
122 /* update the plugin display */
123 GtkRebuildCList( p_playlist_clist, p_main->p_playlist );
125 /* end current item, select added item */
126 if( p_intf->p_input != NULL )
128 p_intf->p_input->b_eof = 1;
131 intf_PlaylistJumpto( p_main->p_playlist, i_end - 1 );
134 /*****************************************************************************
135 * Open disc callbacks
136 *****************************************************************************
137 * The following callbacks are related to the disc manager.
138 *****************************************************************************/
139 gboolean GtkDiscOpenShow( GtkWidget *widget,
140 GdkEventButton *event,
143 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), (char*)user_data );
145 if( !GTK_IS_WIDGET( p_intf->p_sys->p_disc ) )
147 p_intf->p_sys->p_disc = create_intf_disc();
148 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_disc ),
152 gtk_widget_show( p_intf->p_sys->p_disc );
153 gdk_window_raise( p_intf->p_sys->p_disc->window );
159 void GtkDiscOpenDvd( GtkToggleButton * togglebutton, gpointer user_data )
161 if( togglebutton->active )
164 GTK_ENTRY( lookup_widget( GTK_WIDGET(togglebutton), "disc_name" ) ),
165 main_GetPszVariable( INPUT_DVD_DEVICE_VAR, INPUT_DVD_DEVICE_DEFAULT )
170 void GtkDiscOpenVcd( GtkToggleButton * togglebutton, gpointer user_data )
172 if( togglebutton->active )
175 GTK_ENTRY( lookup_widget( GTK_WIDGET(togglebutton), "disc_name" ) ),
176 main_GetPszVariable( INPUT_VCD_DEVICE_VAR, INPUT_VCD_DEVICE_DEFAULT )
181 void GtkDiscOpenOk( GtkButton * button, gpointer user_data )
183 intf_thread_t * p_intf = GetIntf( GTK_WIDGET(button), "intf_disc" );
184 GtkCList * p_playlist_clist;
185 char * psz_device, *psz_source, *psz_method;
186 int i_end = p_main->p_playlist->i_size;
188 gtk_widget_hide( p_intf->p_sys->p_disc );
189 psz_device = gtk_entry_get_text( GTK_ENTRY( lookup_widget(
190 GTK_WIDGET(button), "disc_name" ) ) );
192 /* "dvd:foo" has size 5 + strlen(foo) */
193 psz_source = malloc( 3 /* "dvd" */ + 1 /* ":" */
194 + strlen( psz_device ) + 1 /* "\0" */ );
195 if( psz_source == NULL )
200 /* Check which method was activated */
201 if( GTK_TOGGLE_BUTTON( lookup_widget( GTK_WIDGET(button),
202 "disc_dvd" ) )->active )
206 else if( GTK_TOGGLE_BUTTON( lookup_widget( GTK_WIDGET(button),
207 "disc_vcd" ) )->active )
213 intf_ErrMsg( "intf error: unknown disc type toggle button position" );
218 /* Select title and chapter */
219 main_PutIntVariable( INPUT_TITLE_VAR, gtk_spin_button_get_value_as_int(
220 GTK_SPIN_BUTTON( lookup_widget(
221 GTK_WIDGET(button), "disc_title" ) ) ) );
223 main_PutIntVariable( INPUT_CHAPTER_VAR, gtk_spin_button_get_value_as_int(
224 GTK_SPIN_BUTTON( lookup_widget(
225 GTK_WIDGET(button), "disc_chapter" ) ) ) );
227 /* Build source name and add it to playlist */
228 sprintf( psz_source, "%s:%s", psz_method, psz_device );
229 intf_PlaylistAdd( p_main->p_playlist, PLAYLIST_END, psz_source );
232 /* catch the GTK CList */
233 p_playlist_clist = GTK_CLIST( gtk_object_get_data(
234 GTK_OBJECT( p_intf->p_sys->p_playlist ), "playlist_clist" ) );
236 /* update the display */
237 GtkRebuildCList( p_playlist_clist, p_main->p_playlist );
239 /* stop current item, select added item */
240 if( p_intf->p_input != NULL )
242 p_intf->p_input->b_eof = 1;
245 intf_PlaylistJumpto( p_main->p_playlist, i_end - 1 );
249 void GtkDiscOpenCancel( GtkButton * button, gpointer user_data )
251 gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
255 /*****************************************************************************
256 * Network stream callbacks
257 *****************************************************************************
258 * The following callbacks are related to the network stream manager.
259 *****************************************************************************/
260 gboolean GtkNetworkOpenShow( GtkWidget *widget,
261 GdkEventButton *event,
264 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), (char*)user_data );
266 if( !GTK_IS_WIDGET( p_intf->p_sys->p_network ) )
268 p_intf->p_sys->p_network = create_intf_network();
269 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_network ),
272 gtk_entry_set_text( GTK_ENTRY( gtk_object_get_data(
273 GTK_OBJECT( p_intf->p_sys->p_network ), "network_server" ) ),
274 main_GetPszVariable( INPUT_SERVER_VAR,
275 INPUT_SERVER_DEFAULT ) );
277 gtk_spin_button_set_value( GTK_SPIN_BUTTON( gtk_object_get_data(
278 GTK_OBJECT( p_intf->p_sys->p_network ), "network_port" ) ),
279 main_GetIntVariable( INPUT_PORT_VAR,
280 INPUT_PORT_DEFAULT ) );
282 gtk_entry_set_text( GTK_ENTRY( gtk_object_get_data(
283 GTK_OBJECT( p_intf->p_sys->p_network ), "network_broadcast" ) ),
284 main_GetPszVariable( INPUT_BCAST_ADDR_VAR,
285 INPUT_BCAST_ADDR_DEFAULT ) );
287 gtk_entry_set_text( GTK_ENTRY( gtk_object_get_data(
288 GTK_OBJECT( p_intf->p_sys->p_network ), "network_channel" ) ),
289 main_GetPszVariable( INPUT_CHANNEL_SERVER_VAR,
290 INPUT_CHANNEL_SERVER_DEFAULT ) );
292 gtk_spin_button_set_value( GTK_SPIN_BUTTON( gtk_object_get_data(
293 GTK_OBJECT( p_intf->p_sys->p_network ), "network_channel_port" ) ),
294 main_GetIntVariable( INPUT_CHANNEL_PORT_VAR,
295 INPUT_CHANNEL_PORT_DEFAULT ) );
297 gtk_toggle_button_set_active( gtk_object_get_data( GTK_OBJECT(
298 p_intf->p_sys->p_network ), "network_channel_check" ),
299 main_GetIntVariable( INPUT_NETWORK_CHANNEL_VAR,
300 INPUT_NETWORK_CHANNEL_DEFAULT ) );
302 gtk_toggle_button_set_active( gtk_object_get_data( GTK_OBJECT(
303 p_intf->p_sys->p_network ), "network_broadcast_check" ),
304 main_GetIntVariable( INPUT_BROADCAST_VAR,
305 INPUT_BROADCAST_DEFAULT ) );
308 gtk_widget_show( p_intf->p_sys->p_network );
309 gdk_window_raise( p_intf->p_sys->p_network->window );
315 void GtkNetworkOpenOk( GtkButton *button, gpointer user_data )
317 intf_thread_t * p_intf = GetIntf( GTK_WIDGET(button), "intf_network" );
318 GtkCList * p_playlist_clist;
319 char * psz_source, *psz_server, *psz_protocol;
321 boolean_t b_broadcast;
323 int i_end = p_main->p_playlist->i_size;
325 gtk_widget_hide( p_intf->p_sys->p_network );
326 psz_server = gtk_entry_get_text( GTK_ENTRY( lookup_widget(
327 GTK_WIDGET(button), "network_server" ) ) );
329 /* select added item */
330 if( p_intf->p_input != NULL )
332 p_intf->p_input->b_eof = 1;
335 /* Check which protocol was activated */
336 if( GTK_TOGGLE_BUTTON( lookup_widget( GTK_WIDGET(button),
337 "network_ts" ) )->active )
341 else if( GTK_TOGGLE_BUTTON( lookup_widget( GTK_WIDGET(button),
342 "network_rtp" ) )->active )
344 psz_protocol = "rtp";
348 intf_ErrMsg( "intf error: unknown protocol toggle button position" );
352 /* Manage channel server */
353 b_channel = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(
354 lookup_widget( GTK_WIDGET(button), "network_channel_check" ) ) );
355 main_PutIntVariable( INPUT_NETWORK_CHANNEL_VAR, b_channel );
359 unsigned int i_channel_port;
361 if( p_main->p_channel == NULL )
363 network_ChannelCreate();
366 psz_channel = gtk_entry_get_text( GTK_ENTRY( lookup_widget(
367 GTK_WIDGET(button), "network_channel" ) ) );
368 i_channel_port = gtk_spin_button_get_value_as_int( GTK_SPIN_BUTTON(
369 lookup_widget( GTK_WIDGET(button), "network_channel_port" ) ) );
371 main_PutPszVariable( INPUT_CHANNEL_SERVER_VAR, psz_channel );
372 if( i_channel_port < 65536 )
374 main_PutIntVariable( INPUT_CHANNEL_PORT_VAR, i_channel_port );
377 p_intf->p_sys->b_playing = 1;
382 /* Get the port number and make sure it will not
383 * overflow 5 characters */
384 i_port = gtk_spin_button_get_value_as_int( GTK_SPIN_BUTTON(
385 lookup_widget( GTK_WIDGET(button), "network_port" ) ) );
388 intf_ErrMsg( "intf error: invalid port %i", i_port );
391 /* do we have a broadcast address */
392 b_broadcast = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(
393 lookup_widget( GTK_WIDGET(button), "network_broadcast_check" ) ) );
396 char * psz_broadcast;
397 psz_broadcast = gtk_entry_get_text( GTK_ENTRY( lookup_widget(
398 GTK_WIDGET(button), "network_broadcast" ) ) );
399 /* Allocate room for "protocol://server:port" */
400 psz_source = malloc( strlen( psz_protocol ) + 3 /* "://" */
401 + strlen( psz_server ) + 1 /* ":" */
403 + strlen( psz_broadcast ) + 2 /* "::" */
405 if( psz_source == NULL )
410 /* Build source name and add it to playlist */
411 sprintf( psz_source, "%s://%s:%i/%s", psz_protocol,
418 /* Allocate room for "protocol://server:port" */
419 psz_source = malloc( strlen( psz_protocol ) + 3 /* "://" */
420 + strlen( psz_server ) + 1 /* ":" */
421 + 5 /* 0-65535 */ + 1 /* "\0" */ );
422 if( psz_source == NULL )
427 /* Build source name and add it to playlist */
428 sprintf( psz_source, "%s://%s:%i",
429 psz_protocol, psz_server, i_port );
432 intf_PlaylistAdd( p_main->p_playlist, PLAYLIST_END, psz_source );
435 /* catch the GTK CList */
436 p_playlist_clist = GTK_CLIST( gtk_object_get_data(
437 GTK_OBJECT( p_intf->p_sys->p_playlist ), "playlist_clist" ) );
438 /* update the display */
439 GtkRebuildCList( p_playlist_clist, p_main->p_playlist );
441 intf_PlaylistJumpto( p_main->p_playlist, i_end - 1 );
445 void GtkNetworkOpenCancel( GtkButton * button, gpointer user_data)
447 gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
451 void GtkNetworkOpenBroadcast( GtkToggleButton * togglebutton,
454 GtkWidget * p_network;
456 p_network = gtk_widget_get_toplevel( GTK_WIDGET (togglebutton) );
458 gtk_widget_set_sensitive( gtk_object_get_data( GTK_OBJECT( p_network ),
459 "network_broadcast_combo" ),
460 gtk_toggle_button_get_active( togglebutton ) );
462 gtk_widget_set_sensitive( gtk_object_get_data( GTK_OBJECT( p_network ),
463 "network_broadcast" ),
464 gtk_toggle_button_get_active( togglebutton ) );
468 void GtkNetworkOpenChannel( GtkToggleButton * togglebutton,
471 GtkWidget * p_network;
473 boolean_t b_broadcast;
475 p_network = gtk_widget_get_toplevel( GTK_WIDGET (togglebutton) );
476 b_channel = gtk_toggle_button_get_active( togglebutton );
477 b_broadcast = gtk_toggle_button_get_active( gtk_object_get_data(
478 GTK_OBJECT( p_network ), "network_broadcast_check" ) );
480 gtk_widget_set_sensitive( gtk_object_get_data( GTK_OBJECT( p_network ),
481 "network_channel_combo" ), b_channel ) ;
483 gtk_widget_set_sensitive( gtk_object_get_data( GTK_OBJECT( p_network ),
484 "network_channel" ), b_channel );
486 gtk_widget_set_sensitive( gtk_object_get_data( GTK_OBJECT( p_network ),
487 "network_channel_port" ), b_channel );
489 gtk_widget_set_sensitive( gtk_object_get_data( GTK_OBJECT( p_network ),
490 "network_channel_port_label" ), b_channel );
492 gtk_widget_set_sensitive( gtk_object_get_data( GTK_OBJECT( p_network ),
493 "network_server_combo" ), ! b_channel );
495 gtk_widget_set_sensitive( gtk_object_get_data( GTK_OBJECT( p_network ),
496 "network_server_label" ), ! b_channel );
498 gtk_widget_set_sensitive( gtk_object_get_data( GTK_OBJECT( p_network ),
499 "network_server" ), ! b_channel );
501 gtk_widget_set_sensitive( gtk_object_get_data( GTK_OBJECT( p_network ),
502 "network_port_label" ), ! b_channel );
504 gtk_widget_set_sensitive( gtk_object_get_data( GTK_OBJECT( p_network ),
505 "network_port" ), ! b_channel );
507 gtk_widget_set_sensitive( gtk_object_get_data( GTK_OBJECT( p_network ),
508 "network_broadcast_check" ), ! b_channel );
510 gtk_widget_set_sensitive( gtk_object_get_data( GTK_OBJECT( p_network ),
511 "network_broadcast_combo" ), b_broadcast && ! b_channel );
513 gtk_widget_set_sensitive( gtk_object_get_data( GTK_OBJECT( p_network ),
514 "network_broadcast" ), b_broadcast && ! b_channel );
518 /****************************************************************************
519 * Callbacks for menuitem
520 ****************************************************************************/
521 void GtkFileOpenActivate( GtkMenuItem * menuitem, gpointer user_data )
523 GtkFileOpenShow( GTK_WIDGET( menuitem ), NULL, user_data );
527 void GtkDiscOpenActivate( GtkMenuItem * menuitem, gpointer user_data )
529 GtkDiscOpenShow( GTK_WIDGET( menuitem ), NULL, user_data );
533 void GtkNetworkOpenActivate( GtkMenuItem * menuitem, gpointer user_data )
535 GtkNetworkOpenShow( GTK_WIDGET( menuitem ), NULL, user_data );