1 /*****************************************************************************
2 * gtk_open.c : functions to handle file/disc/network open widgets.
3 *****************************************************************************
4 * Copyright (C) 2000, 2001 VideoLAN
5 * $Id: open.c,v 1.8 2003/01/10 17:30:18 lool 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 */
34 #ifdef MODULE_NAME_IS_gnome
42 #include "gtk_callbacks.h"
43 #include "gtk_interface.h"
44 #include "gtk_support.h"
51 static void GtkOpenShow( intf_thread_t *, int );
53 static void GtkFileOpenChanged ( GtkWidget *, gpointer );
54 static void GtkDiscOpenChanged ( GtkWidget *, gpointer );
55 static void GtkNetworkOpenChanged ( GtkWidget *, gpointer );
56 static void GtkSatOpenChanged ( GtkWidget *, gpointer );
58 /*****************************************************************************
59 * File requester callbacks
60 *****************************************************************************
61 * The following callbacks are related to the file requester.
62 *****************************************************************************/
63 void GtkFileShow( GtkButton * button, gpointer user_data )
65 GtkWidget * p_file = create_intf_file();
67 gtk_object_set_data( GTK_OBJECT(p_file), "p_intf",
68 GtkGetIntf( button ) );
70 gtk_widget_show( p_file );
71 gdk_window_raise( p_file->window );
74 void GtkFileOk( GtkButton * button, gpointer user_data )
76 GtkWidget * p_file = gtk_widget_get_toplevel( GTK_WIDGET (button) );
79 intf_thread_t * p_intf = GtkGetIntf( button );
81 /* add the new file to the dialog box */
83 gtk_file_selection_get_filename( GTK_FILE_SELECTION( p_file ) );
84 gtk_entry_set_text( GTK_ENTRY( lookup_widget( p_intf->p_sys->p_open,
87 gtk_widget_destroy( p_file );
90 void GtkFileCancel( GtkButton * button, gpointer user_data )
92 gtk_widget_destroy( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
95 /*****************************************************************************
97 *****************************************************************************
98 * The following callbacks are related to the file tab.
99 *****************************************************************************/
100 gboolean GtkFileOpenShow( GtkWidget *widget,
103 GtkOpenShow( GtkGetIntf( widget ), 0 );
108 static void GtkFileOpenChanged( GtkWidget * button, gpointer user_data )
112 p_target = g_string_new( "file://" );
113 g_string_append( p_target,
114 gtk_entry_get_text( GTK_ENTRY( lookup_widget(
115 GTK_WIDGET(button), "entry_file" ) ) ) );
116 gtk_entry_set_text( GTK_ENTRY( lookup_widget(
117 GTK_WIDGET(button), "entry_open" ) ),
119 g_string_free( p_target, TRUE );
122 /*****************************************************************************
123 * Open disc callbacks
124 *****************************************************************************
125 * The following callbacks are related to the disc manager.
126 *****************************************************************************/
127 gboolean GtkDiscOpenShow( GtkWidget *widget,
130 GtkOpenShow( GtkGetIntf( widget ), 1 );
135 void GtkDiscOpenDvd( GtkToggleButton * togglebutton, gpointer user_data )
137 intf_thread_t * p_intf = GtkGetIntf( togglebutton );
140 if( togglebutton->active
141 && (psz_device = config_GetPsz( p_intf, "dvd" )) )
144 GTK_ENTRY( lookup_widget( GTK_WIDGET(togglebutton),
145 "disc_name" ) ), psz_device );
150 void GtkDiscOpenVcd( GtkToggleButton * togglebutton, gpointer user_data )
152 intf_thread_t * p_intf = GtkGetIntf( togglebutton );
155 if( togglebutton->active
156 && (psz_device = config_GetPsz( p_intf, "vcd" )) )
159 GTK_ENTRY( lookup_widget( GTK_WIDGET(togglebutton),
160 "disc_name" ) ), psz_device );
165 static void GtkDiscOpenChanged( GtkWidget * button, gpointer user_data )
167 GString * p_target = g_string_new( "" );
169 if( GTK_TOGGLE_BUTTON( lookup_widget( GTK_WIDGET(button),
170 "disc_dvd" ) )->active )
172 g_string_append( p_target, "dvd://" );
174 else if( GTK_TOGGLE_BUTTON( lookup_widget( GTK_WIDGET(button),
175 "disc_vcd" ) )->active )
177 g_string_append( p_target, "vcd://" );
180 g_string_append( p_target,
181 gtk_entry_get_text( GTK_ENTRY( lookup_widget(
182 GTK_WIDGET(button), "disc_name" ) ) ) );
183 g_string_sprintfa( p_target, "@%i,%i",
184 gtk_spin_button_get_value_as_int(
185 GTK_SPIN_BUTTON( lookup_widget(
186 GTK_WIDGET(button), "disc_title" ) ) ),
187 gtk_spin_button_get_value_as_int(
188 GTK_SPIN_BUTTON( lookup_widget(
189 GTK_WIDGET(button), "disc_chapter" ) ) ) );
191 gtk_entry_set_text( GTK_ENTRY( lookup_widget(
192 GTK_WIDGET(button), "entry_open" ) ),
194 g_string_free( p_target, TRUE );
197 /*****************************************************************************
198 * Network stream callbacks
199 *****************************************************************************
200 * The following callbacks are related to the network stream manager.
201 *****************************************************************************/
202 gboolean GtkNetworkOpenShow( GtkWidget *widget,
205 GtkOpenShow( GtkGetIntf( widget ), 2 );
210 static void GtkNetworkOpenChanged( GtkWidget *button, gpointer user_data )
212 intf_thread_t * p_intf = GtkGetIntf( button );
213 GString * p_target = g_string_new( "" );
216 vlc_bool_t b_channel;
218 /* Manage channel server */
219 b_channel = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(
220 lookup_widget( GTK_WIDGET(button), "network_channel" ) ) );
221 config_PutInt( p_intf, "network-channel", b_channel );
223 #define SELECTED( s ) GTK_TOGGLE_BUTTON( lookup_widget( GTK_WIDGET(button), \
225 /* Check which option was chosen */
226 if( SELECTED( "network_udp" ) )
228 g_string_append( p_target, "udp://" );
229 i_port = gtk_spin_button_get_value_as_int( GTK_SPIN_BUTTON(
230 lookup_widget( GTK_WIDGET(button),
231 "network_udp_port" ) ) );
234 g_string_sprintfa( p_target, "@:%i", i_port );
237 else if( SELECTED( "network_multicast" ) )
239 g_string_sprintfa( p_target, "udp://@%s",
240 gtk_entry_get_text( GTK_ENTRY(
241 lookup_widget( GTK_WIDGET(button),
242 "network_multicast_address" ) ) ) );
243 i_port = gtk_spin_button_get_value_as_int( GTK_SPIN_BUTTON(
244 lookup_widget( GTK_WIDGET(button),
245 "network_multicast_port" ) ) );
248 g_string_sprintfa( p_target, ":%i", i_port );
251 else if( SELECTED( "network_channel" ) )
254 unsigned int i_channel_port;
256 if( p_intf->p_vlc->p_channel == NULL )
258 network_ChannelCreate( p_intf );
261 psz_channel = gtk_entry_get_text( GTK_ENTRY( lookup_widget(
262 GTK_WIDGET(button), "network_channel_address" ) ) );
263 i_channel_port = gtk_spin_button_get_value_as_int( GTK_SPIN_BUTTON(
264 lookup_widget( GTK_WIDGET(button), "network_channel_port" ) ) );
266 config_PutPsz( p_intf, "channel-server", psz_channel );
267 if( i_channel_port < 65536 )
269 config_PutInt( p_intf, "channel-port", i_channel_port );
272 /* FIXME: we should use a playlist server instead */
273 g_string_append( p_target, "udp://" );
275 else if( SELECTED( "network_http" ) )
277 g_string_assign( p_target,
278 gtk_entry_get_text( GTK_ENTRY( lookup_widget(
279 GTK_WIDGET(button), "network_http_url" ) ) ) );
282 gtk_entry_set_text( GTK_ENTRY( lookup_widget(
283 GTK_WIDGET(button), "entry_open" ) ),
285 g_string_free( p_target, TRUE );
288 void GtkNetworkOpenUDP( GtkToggleButton *togglebutton,
293 p_open = gtk_widget_get_toplevel( GTK_WIDGET (togglebutton) );
295 gtk_widget_set_sensitive( gtk_object_get_data( GTK_OBJECT( p_open ),
296 "network_udp_port_label" ),
297 gtk_toggle_button_get_active( togglebutton ) );
298 gtk_widget_set_sensitive( gtk_object_get_data( GTK_OBJECT( p_open ),
299 "network_udp_port" ),
300 gtk_toggle_button_get_active( togglebutton ) );
302 GtkNetworkOpenChanged( GTK_WIDGET( togglebutton ), user_data );
305 void GtkNetworkOpenMulticast( GtkToggleButton *togglebutton,
310 p_open = gtk_widget_get_toplevel( GTK_WIDGET (togglebutton) );
311 gtk_widget_set_sensitive( gtk_object_get_data( GTK_OBJECT( p_open ),
312 "network_multicast_address_label" ),
313 gtk_toggle_button_get_active( togglebutton ) );
314 gtk_widget_set_sensitive( gtk_object_get_data( GTK_OBJECT( p_open ),
315 "network_multicast_address_combo" ),
316 gtk_toggle_button_get_active( togglebutton ) );
318 gtk_widget_set_sensitive( gtk_object_get_data( GTK_OBJECT( p_open ),
319 "network_multicast_port_label" ),
320 gtk_toggle_button_get_active( togglebutton ) );
321 gtk_widget_set_sensitive( gtk_object_get_data( GTK_OBJECT( p_open ),
322 "network_multicast_port" ),
323 gtk_toggle_button_get_active( togglebutton ) );
325 GtkNetworkOpenChanged( GTK_WIDGET( togglebutton ), user_data );
329 void GtkNetworkOpenChannel( GtkToggleButton *togglebutton,
334 p_open = gtk_widget_get_toplevel( GTK_WIDGET (togglebutton) );
335 gtk_widget_set_sensitive( gtk_object_get_data( GTK_OBJECT( p_open ),
336 "network_channel_address_label" ),
337 gtk_toggle_button_get_active( togglebutton ) );
338 gtk_widget_set_sensitive( gtk_object_get_data( GTK_OBJECT( p_open ),
339 "network_channel_address_combo" ),
340 gtk_toggle_button_get_active( togglebutton ) );
342 gtk_widget_set_sensitive( gtk_object_get_data( GTK_OBJECT( p_open ),
343 "network_channel_port_label" ),
344 gtk_toggle_button_get_active( togglebutton ) );
345 gtk_widget_set_sensitive( gtk_object_get_data( GTK_OBJECT( p_open ),
346 "network_channel_port" ),
347 gtk_toggle_button_get_active( togglebutton ) );
349 GtkNetworkOpenChanged( GTK_WIDGET( togglebutton ), user_data );
352 void GtkNetworkOpenHTTP( GtkToggleButton *togglebutton,
357 p_open = gtk_widget_get_toplevel( GTK_WIDGET (togglebutton) );
358 gtk_widget_set_sensitive( gtk_object_get_data( GTK_OBJECT( p_open ),
359 "network_http_url_label" ),
360 gtk_toggle_button_get_active( togglebutton ) );
361 gtk_widget_set_sensitive( gtk_object_get_data( GTK_OBJECT( p_open ),
362 "network_http_url" ),
363 gtk_toggle_button_get_active( togglebutton ) );
365 GtkNetworkOpenChanged( GTK_WIDGET( togglebutton ), user_data );
368 /*****************************************************************************
369 * Open satellite callbacks
370 *****************************************************************************
371 * The following callbacks are related to the satellite card manager.
372 *****************************************************************************/
373 gboolean GtkSatOpenShow( GtkWidget *widget,
376 GtkOpenShow( GtkGetIntf( widget ), 3 );
381 static void GtkSatOpenChanged( GtkWidget * button, gpointer user_data )
383 GString * p_target = g_string_new( "" );
385 g_string_sprintfa( p_target, "%s://%d,%d,%ld,%d", "satellite",
386 gtk_spin_button_get_value_as_int(
387 GTK_SPIN_BUTTON( lookup_widget(
388 GTK_WIDGET(button), "sat_freq" ) ) ),
389 !GTK_TOGGLE_BUTTON( lookup_widget( GTK_WIDGET( button ),
390 "sat_pol_vert" ) )->active,
391 strtol( gtk_entry_get_text( GTK_ENTRY( GTK_COMBO(
392 lookup_widget( GTK_WIDGET( button ), "sat_fec" )
393 )->entry ) ), NULL, 10 ),
394 gtk_spin_button_get_value_as_int(
395 GTK_SPIN_BUTTON( lookup_widget(
396 GTK_WIDGET(button), "sat_srate" ) ) ) );
398 gtk_entry_set_text( GTK_ENTRY( lookup_widget(
399 GTK_WIDGET(button), "entry_open" ) ),
401 g_string_free( p_target, TRUE );
405 GtkSatOpenToggle (GtkToggleButton *togglebutton,
408 if( togglebutton->active )
410 GtkSatOpenChanged( GTK_WIDGET( togglebutton ), user_data );
414 /******************************
415 ******************************/
417 static void GtkOpenShow( intf_thread_t *p_intf, int i_page )
420 GtkWidget *p_notebook;
422 /* If we have already created this window, do nothing */
423 if( GTK_IS_WIDGET( p_intf->p_sys->p_open ) )
428 p_intf->p_sys->p_open = create_intf_open();
429 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_open ),
433 psz_var = config_GetPsz( p_intf, "search-path" );
436 gtk_file_selection_set_filename( GTK_FILE_SELECTION(
437 p_intf->p_sys->p_open ), psz_var );
442 psz_var = config_GetPsz( p_intf, "dvd" );
445 gtk_entry_set_text( GTK_ENTRY( gtk_object_get_data(
446 GTK_OBJECT( p_intf->p_sys->p_open ), "disc_name" ) ),
452 gtk_spin_button_set_value( GTK_SPIN_BUTTON( gtk_object_get_data(
453 GTK_OBJECT( p_intf->p_sys->p_open ), "network_udp_port" ) ),
454 config_GetInt( p_intf, "server-port" ) );
456 psz_var = config_GetPsz( p_intf, "channel-server" );
459 gtk_entry_set_text( GTK_ENTRY( gtk_object_get_data(
460 GTK_OBJECT( p_intf->p_sys->p_open ), "network_channel_address" ) ),
465 gtk_entry_set_text( GTK_ENTRY( gtk_object_get_data(
466 GTK_OBJECT( p_intf->p_sys->p_open ), "network_http_url" ) ),
469 gtk_spin_button_set_value( GTK_SPIN_BUTTON( gtk_object_get_data(
470 GTK_OBJECT( p_intf->p_sys->p_open ), "network_channel_port" ) ),
471 config_GetInt( p_intf, "channel-port" ) );
473 gtk_toggle_button_set_active( gtk_object_get_data(
474 GTK_OBJECT( p_intf->p_sys->p_open ), "network_channel" ),
475 config_GetInt( p_intf, "network-channel" ) );
477 /* Satellite stuff */
478 psz_var = config_GetPsz( p_intf, "frequency" );
481 gtk_entry_set_text( GTK_ENTRY( gtk_object_get_data(
482 GTK_OBJECT( p_intf->p_sys->p_open ), "sat_freq" ) ),
487 psz_var = config_GetPsz( p_intf, "symbol-rate" );
490 gtk_entry_set_text( GTK_ENTRY( gtk_object_get_data(
491 GTK_OBJECT( p_intf->p_sys->p_open ), "sat_srate" ) ),
496 /* Set the right page */
498 p_notebook = lookup_widget( GTK_WIDGET( p_intf->p_sys->p_open ),
500 gtk_notebook_set_page( GTK_NOTEBOOK( p_notebook ), i_page );
502 gtk_widget_show( p_intf->p_sys->p_open );
503 gdk_window_raise( p_intf->p_sys->p_open->window );
506 void GtkOpenOk( GtkButton * button, gpointer user_data )
508 /* Check what was pressed */
509 intf_thread_t * p_intf = GtkGetIntf( button );
510 playlist_t * p_playlist;
511 GtkCList * p_playlist_clist;
514 /* Hide the dialog box */
515 gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
517 /* Update the playlist */
518 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
519 if( p_playlist == NULL )
524 psz_target = gtk_entry_get_text( GTK_ENTRY( lookup_widget(
525 GTK_WIDGET(button), "entry_open" ) ) );
526 playlist_Add( p_playlist, (char*)psz_target,
527 PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
529 /* catch the GTK CList */
530 p_playlist_clist = GTK_CLIST( gtk_object_get_data(
531 GTK_OBJECT( p_intf->p_sys->p_playwin ), "playlist_clist" ) );
532 /* update the plugin display */
533 GtkRebuildCList( p_playlist_clist, p_playlist );
535 vlc_object_release( p_playlist );
537 /* Enable the channel box when network channel is selected */
538 if( GTK_TOGGLE_BUTTON( lookup_widget( GTK_WIDGET(button),
539 "network_channel" ) )->active )
541 GtkWidget * p_network_box;
542 GtkWidget * p_channel;
545 p_network_box = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
546 p_intf->p_sys->p_window ), "network_box" ) );
547 gtk_widget_show( GTK_WIDGET( p_network_box ) );
548 p_label = gtk_object_get_data( GTK_OBJECT(
549 p_intf->p_sys->p_window ),
551 gtk_widget_hide( GTK_WIDGET( p_label ) );
553 p_channel = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
554 p_intf->p_sys->p_window ), "network_channel_box" ) );
555 if( config_GetInt( p_intf, "network-channel" ) )
557 gtk_widget_show( GTK_WIDGET( p_channel ) );
561 gtk_widget_hide( GTK_WIDGET( p_channel ) );
567 void GtkOpenCancel( GtkButton * button, gpointer user_data )
569 gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
572 void GtkOpenChanged( GtkWidget * button, gpointer user_data )
574 intf_thread_t * p_intf = GtkGetIntf( button );
575 GtkWidget *p_notebook;
578 p_notebook = lookup_widget( GTK_WIDGET( p_intf->p_sys->p_open ),
580 i_page = gtk_notebook_get_current_page( GTK_NOTEBOOK( p_notebook ) );
585 GtkFileOpenChanged( button, NULL );
588 GtkDiscOpenChanged( button, NULL );
591 GtkNetworkOpenChanged( button, NULL );
594 GtkSatOpenChanged( button, NULL );