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.12 2001/12/30 07:09:55 sam 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 ) )
69 p_intf->p_sys->p_fileopen = create_intf_fileopen();
70 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_fileopen ),
73 gtk_file_selection_set_filename( GTK_FILE_SELECTION(
74 p_intf->p_sys->p_fileopen ),
75 main_GetPszVariable( INTF_PATH_VAR, INTF_PATH_DEFAULT ) );
78 gtk_widget_show( p_intf->p_sys->p_fileopen );
79 gdk_window_raise( p_intf->p_sys->p_fileopen->window );
85 void GtkFileOpenCancel( GtkButton * button, gpointer user_data )
87 gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
90 void GtkFileOpenOk( GtkButton * button, gpointer user_data )
92 intf_thread_t * p_intf = GetIntf( GTK_WIDGET(button), "intf_fileopen" );
93 GtkCList * p_playlist_clist;
94 GtkWidget * p_filesel;
96 int i_end = p_main->p_playlist->i_size;
98 /* hide the file selector */
99 p_filesel = gtk_widget_get_toplevel( GTK_WIDGET(button) );
100 gtk_widget_hide( p_filesel );
102 /* add the new file to the interface playlist */
104 gtk_file_selection_get_filename( GTK_FILE_SELECTION( p_filesel ) );
105 intf_PlaylistAdd( p_main->p_playlist, PLAYLIST_END, (char*)psz_filename );
107 /* catch the GTK CList */
108 p_playlist_clist = GTK_CLIST( gtk_object_get_data(
109 GTK_OBJECT( p_intf->p_sys->p_playlist ), "playlist_clist" ) );
110 /* update the plugin display */
111 GtkRebuildCList( p_playlist_clist, p_main->p_playlist );
113 /* end current item, select added item */
114 if( p_intf->p_input != NULL )
116 p_intf->p_input->b_eof = 1;
119 intf_PlaylistJumpto( p_main->p_playlist, i_end - 1 );
122 /*****************************************************************************
123 * Open disc callbacks
124 *****************************************************************************
125 * The following callbacks are related to the disc manager.
126 *****************************************************************************/
127 gboolean GtkDiscOpenShow( GtkWidget *widget,
128 GdkEventButton *event,
131 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), (char*)user_data );
133 if( !GTK_IS_WIDGET( p_intf->p_sys->p_disc ) )
135 p_intf->p_sys->p_disc = create_intf_disc();
136 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_disc ),
140 gtk_widget_show( p_intf->p_sys->p_disc );
141 gdk_window_raise( p_intf->p_sys->p_disc->window );
147 void GtkDiscOpenDvd( GtkToggleButton * togglebutton, gpointer user_data )
149 if( togglebutton->active )
152 GTK_ENTRY( lookup_widget( GTK_WIDGET(togglebutton), "disc_name" ) ),
153 main_GetPszVariable( INPUT_DVD_DEVICE_VAR, INPUT_DVD_DEVICE_DEFAULT )
158 void GtkDiscOpenVcd( GtkToggleButton * togglebutton, gpointer user_data )
160 if( togglebutton->active )
163 GTK_ENTRY( lookup_widget( GTK_WIDGET(togglebutton), "disc_name" ) ),
164 main_GetPszVariable( INPUT_VCD_DEVICE_VAR, INPUT_VCD_DEVICE_DEFAULT )
169 void GtkDiscOpenOk( GtkButton * button, gpointer user_data )
171 intf_thread_t * p_intf = GetIntf( GTK_WIDGET(button), "intf_disc" );
172 GtkCList * p_playlist_clist;
173 char * psz_device, *psz_source, *psz_method;
174 int i_end = p_main->p_playlist->i_size;
176 gtk_widget_hide( p_intf->p_sys->p_disc );
177 psz_device = gtk_entry_get_text( GTK_ENTRY( lookup_widget(
178 GTK_WIDGET(button), "disc_name" ) ) );
180 /* "dvd:foo" has size 5 + strlen(foo) */
181 psz_source = malloc( 3 /* "dvd" */ + 1 /* ":" */
182 + strlen( psz_device ) + 1 /* "\0" */ );
183 if( psz_source == NULL )
188 /* Check which method was activated */
189 if( GTK_TOGGLE_BUTTON( lookup_widget( GTK_WIDGET(button),
190 "disc_dvd" ) )->active )
194 else if( GTK_TOGGLE_BUTTON( lookup_widget( GTK_WIDGET(button),
195 "disc_vcd" ) )->active )
201 intf_ErrMsg( "intf error: unknown disc type toggle button position" );
206 /* Select title and chapter */
207 main_PutIntVariable( INPUT_TITLE_VAR, gtk_spin_button_get_value_as_int(
208 GTK_SPIN_BUTTON( lookup_widget(
209 GTK_WIDGET(button), "disc_title" ) ) ) );
211 main_PutIntVariable( INPUT_CHAPTER_VAR, gtk_spin_button_get_value_as_int(
212 GTK_SPIN_BUTTON( lookup_widget(
213 GTK_WIDGET(button), "disc_chapter" ) ) ) );
215 /* Build source name and add it to playlist */
216 sprintf( psz_source, "%s:%s", psz_method, psz_device );
217 intf_PlaylistAdd( p_main->p_playlist, PLAYLIST_END, psz_source );
220 /* catch the GTK CList */
221 p_playlist_clist = GTK_CLIST( gtk_object_get_data(
222 GTK_OBJECT( p_intf->p_sys->p_playlist ), "playlist_clist" ) );
224 /* update the display */
225 GtkRebuildCList( p_playlist_clist, p_main->p_playlist );
227 /* stop current item, select added item */
228 if( p_intf->p_input != NULL )
230 p_intf->p_input->b_eof = 1;
233 intf_PlaylistJumpto( p_main->p_playlist, i_end - 1 );
237 void GtkDiscOpenCancel( GtkButton * button, gpointer user_data )
239 gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
243 /*****************************************************************************
244 * Network stream callbacks
245 *****************************************************************************
246 * The following callbacks are related to the network stream manager.
247 *****************************************************************************/
248 gboolean GtkNetworkOpenShow( GtkWidget *widget,
249 GdkEventButton *event,
252 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), (char*)user_data );
254 if( !GTK_IS_WIDGET( p_intf->p_sys->p_network ) )
256 p_intf->p_sys->p_network = create_intf_network();
257 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_network ),
260 gtk_entry_set_text( GTK_ENTRY( gtk_object_get_data(
261 GTK_OBJECT( p_intf->p_sys->p_network ), "network_server" ) ),
262 main_GetPszVariable( INPUT_SERVER_VAR,
263 INPUT_SERVER_DEFAULT ) );
265 gtk_spin_button_set_value( GTK_SPIN_BUTTON( gtk_object_get_data(
266 GTK_OBJECT( p_intf->p_sys->p_network ), "network_port" ) ),
267 main_GetIntVariable( INPUT_PORT_VAR,
268 INPUT_PORT_DEFAULT ) );
270 gtk_entry_set_text( GTK_ENTRY( gtk_object_get_data(
271 GTK_OBJECT( p_intf->p_sys->p_network ), "network_broadcast" ) ),
272 main_GetPszVariable( INPUT_BCAST_ADDR_VAR,
273 INPUT_BCAST_ADDR_DEFAULT ) );
275 gtk_entry_set_text( GTK_ENTRY( gtk_object_get_data(
276 GTK_OBJECT( p_intf->p_sys->p_network ), "network_channel" ) ),
277 main_GetPszVariable( INPUT_CHANNEL_SERVER_VAR,
278 INPUT_CHANNEL_SERVER_DEFAULT ) );
280 gtk_spin_button_set_value( GTK_SPIN_BUTTON( gtk_object_get_data(
281 GTK_OBJECT( p_intf->p_sys->p_network ), "network_channel_port" ) ),
282 main_GetIntVariable( INPUT_CHANNEL_PORT_VAR,
283 INPUT_CHANNEL_PORT_DEFAULT ) );
285 gtk_toggle_button_set_active( gtk_object_get_data( GTK_OBJECT(
286 p_intf->p_sys->p_network ), "network_channel_check" ),
287 main_GetIntVariable( INPUT_NETWORK_CHANNEL_VAR,
288 INPUT_NETWORK_CHANNEL_DEFAULT ) );
290 gtk_toggle_button_set_active( gtk_object_get_data( GTK_OBJECT(
291 p_intf->p_sys->p_network ), "network_broadcast_check" ),
292 main_GetIntVariable( INPUT_BROADCAST_VAR,
293 INPUT_BROADCAST_DEFAULT ) );
296 gtk_widget_show( p_intf->p_sys->p_network );
297 gdk_window_raise( p_intf->p_sys->p_network->window );
303 void GtkNetworkOpenOk( GtkButton *button, gpointer user_data )
305 intf_thread_t * p_intf = GetIntf( GTK_WIDGET(button), "intf_network" );
306 GtkCList * p_playlist_clist;
307 char * psz_source, *psz_server, *psz_protocol;
309 boolean_t b_broadcast;
311 int i_end = p_main->p_playlist->i_size;
313 gtk_widget_hide( p_intf->p_sys->p_network );
314 psz_server = gtk_entry_get_text( GTK_ENTRY( lookup_widget(
315 GTK_WIDGET(button), "network_server" ) ) );
317 /* select added item */
318 if( p_intf->p_input != NULL )
320 p_intf->p_input->b_eof = 1;
323 /* Check which protocol was activated */
324 if( GTK_TOGGLE_BUTTON( lookup_widget( GTK_WIDGET(button),
325 "network_ts" ) )->active )
327 psz_protocol = "udpstream";
329 else if( GTK_TOGGLE_BUTTON( lookup_widget( GTK_WIDGET(button),
330 "network_rtp" ) )->active )
332 psz_protocol = "rtp";
336 intf_ErrMsg( "intf error: unknown protocol toggle button position" );
340 /* Manage channel server */
341 b_channel = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(
342 lookup_widget( GTK_WIDGET(button), "network_channel_check" ) ) );
343 main_PutIntVariable( INPUT_NETWORK_CHANNEL_VAR, b_channel );
347 unsigned int i_channel_port;
349 if( p_main->p_channel == NULL )
351 network_ChannelCreate();
354 psz_channel = gtk_entry_get_text( GTK_ENTRY( lookup_widget(
355 GTK_WIDGET(button), "network_channel" ) ) );
356 i_channel_port = gtk_spin_button_get_value_as_int( GTK_SPIN_BUTTON(
357 lookup_widget( GTK_WIDGET(button), "network_channel_port" ) ) );
359 main_PutPszVariable( INPUT_CHANNEL_SERVER_VAR, psz_channel );
360 if( i_channel_port < 65536 )
362 main_PutIntVariable( INPUT_CHANNEL_PORT_VAR, i_channel_port );
365 p_intf->p_sys->b_playing = 1;
370 /* Get the port number and make sure it will not
371 * overflow 5 characters */
372 i_port = gtk_spin_button_get_value_as_int( GTK_SPIN_BUTTON(
373 lookup_widget( GTK_WIDGET(button), "network_port" ) ) );
376 intf_ErrMsg( "intf error: invalid port %i", i_port );
379 /* do we have a broadcast address */
380 b_broadcast = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(
381 lookup_widget( GTK_WIDGET(button), "network_broadcast_check" ) ) );
384 char * psz_broadcast;
385 psz_broadcast = gtk_entry_get_text( GTK_ENTRY( lookup_widget(
386 GTK_WIDGET(button), "network_broadcast" ) ) );
387 /* Allocate room for "protocol://server:port" */
388 psz_source = malloc( strlen( psz_protocol ) + 3 /* "://" */
389 + strlen( psz_server ) + 1 /* ":" */
391 + strlen( psz_broadcast ) + 2 /* "::" */
393 if( psz_source == NULL )
398 /* Build source name and add it to playlist */
399 sprintf( psz_source, "%s://%s:%i/%s", psz_protocol,
406 /* Allocate room for "protocol://server:port" */
407 psz_source = malloc( strlen( psz_protocol ) + 3 /* "://" */
408 + strlen( psz_server ) + 1 /* ":" */
409 + 5 /* 0-65535 */ + 1 /* "\0" */ );
410 if( psz_source == NULL )
415 /* Build source name and add it to playlist */
416 sprintf( psz_source, "%s://%s:%i",
417 psz_protocol, psz_server, i_port );
420 intf_PlaylistAdd( p_main->p_playlist, PLAYLIST_END, psz_source );
423 /* catch the GTK CList */
424 p_playlist_clist = GTK_CLIST( gtk_object_get_data(
425 GTK_OBJECT( p_intf->p_sys->p_playlist ), "playlist_clist" ) );
426 /* update the display */
427 GtkRebuildCList( p_playlist_clist, p_main->p_playlist );
429 intf_PlaylistJumpto( p_main->p_playlist, i_end - 1 );
433 void GtkNetworkOpenCancel( GtkButton * button, gpointer user_data)
435 gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
439 void GtkNetworkOpenBroadcast( GtkToggleButton * togglebutton,
442 GtkWidget * p_network;
444 p_network = gtk_widget_get_toplevel( GTK_WIDGET (togglebutton) );
446 gtk_widget_set_sensitive( gtk_object_get_data( GTK_OBJECT( p_network ),
447 "network_broadcast_combo" ),
448 gtk_toggle_button_get_active( togglebutton ) );
450 gtk_widget_set_sensitive( gtk_object_get_data( GTK_OBJECT( p_network ),
451 "network_broadcast" ),
452 gtk_toggle_button_get_active( togglebutton ) );
456 void GtkNetworkOpenChannel( GtkToggleButton * togglebutton,
459 GtkWidget * p_network;
461 boolean_t b_broadcast;
463 p_network = gtk_widget_get_toplevel( GTK_WIDGET (togglebutton) );
464 b_channel = gtk_toggle_button_get_active( togglebutton );
465 b_broadcast = gtk_toggle_button_get_active( gtk_object_get_data(
466 GTK_OBJECT( p_network ), "network_broadcast_check" ) );
468 gtk_widget_set_sensitive( gtk_object_get_data( GTK_OBJECT( p_network ),
469 "network_channel_combo" ), b_channel ) ;
471 gtk_widget_set_sensitive( gtk_object_get_data( GTK_OBJECT( p_network ),
472 "network_channel" ), b_channel );
474 gtk_widget_set_sensitive( gtk_object_get_data( GTK_OBJECT( p_network ),
475 "network_channel_port" ), b_channel );
477 gtk_widget_set_sensitive( gtk_object_get_data( GTK_OBJECT( p_network ),
478 "network_channel_port_label" ), b_channel );
480 gtk_widget_set_sensitive( gtk_object_get_data( GTK_OBJECT( p_network ),
481 "network_server_combo" ), ! b_channel );
483 gtk_widget_set_sensitive( gtk_object_get_data( GTK_OBJECT( p_network ),
484 "network_server_label" ), ! b_channel );
486 gtk_widget_set_sensitive( gtk_object_get_data( GTK_OBJECT( p_network ),
487 "network_server" ), ! b_channel );
489 gtk_widget_set_sensitive( gtk_object_get_data( GTK_OBJECT( p_network ),
490 "network_port_label" ), ! b_channel );
492 gtk_widget_set_sensitive( gtk_object_get_data( GTK_OBJECT( p_network ),
493 "network_port" ), ! b_channel );
495 gtk_widget_set_sensitive( gtk_object_get_data( GTK_OBJECT( p_network ),
496 "network_broadcast_check" ), ! b_channel );
498 gtk_widget_set_sensitive( gtk_object_get_data( GTK_OBJECT( p_network ),
499 "network_broadcast_combo" ), b_broadcast && ! b_channel );
501 gtk_widget_set_sensitive( gtk_object_get_data( GTK_OBJECT( p_network ),
502 "network_broadcast" ), b_broadcast && ! b_channel );
506 /****************************************************************************
507 * Callbacks for menuitem
508 ****************************************************************************/
509 void GtkFileOpenActivate( GtkMenuItem * menuitem, gpointer user_data )
511 GtkFileOpenShow( GTK_WIDGET( menuitem ), NULL, user_data );
515 void GtkDiscOpenActivate( GtkMenuItem * menuitem, gpointer user_data )
517 GtkDiscOpenShow( GTK_WIDGET( menuitem ), NULL, user_data );
521 void GtkNetworkOpenActivate( GtkMenuItem * menuitem, gpointer user_data )
523 GtkNetworkOpenShow( GTK_WIDGET( menuitem ), NULL, user_data );