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.1 2001/05/15 01:01:44 stef 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 #define MODULE_NAME gtk
26 #include "modules_inner.h"
28 /*****************************************************************************
30 *****************************************************************************/
32 #include <sys/types.h> /* off_t */
44 #include "stream_control.h"
45 #include "input_ext-intf.h"
47 #include "interface.h"
48 #include "intf_playlist.h"
51 #include "gtk_callbacks.h"
52 #include "gtk_interface.h"
53 #include "gtk_support.h"
54 #include "gtk_playlist.h"
59 /*****************************************************************************
61 *****************************************************************************
62 * The following callbacks are related to the file requester.
63 *****************************************************************************/
65 void GtkFileOpenShow( GtkMenuItem * menuitem, gpointer user_data)
67 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), (char*)user_data );
69 /* If we have never used the file selector, open it */
70 if( !GTK_IS_WIDGET( p_intf->p_sys->p_fileopen ) )
72 p_intf->p_sys->p_fileopen = create_intf_fileopen();
73 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_fileopen ),
76 gtk_file_selection_set_filename( GTK_FILE_SELECTION(
77 p_intf->p_sys->p_fileopen ),
78 main_GetPszVariable( INTF_PATH_VAR, INTF_PATH_DEFAULT ) );
81 gtk_widget_show( p_intf->p_sys->p_fileopen );
82 gdk_window_raise( p_intf->p_sys->p_fileopen->window );
87 GtkFileOpenShow (GtkWidget *widget,
88 GdkEventButton *event,
91 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), (char*)user_data );
93 /* If we have never used the file selector, open it */
94 if( !GTK_IS_WIDGET( p_intf->p_sys->p_fileopen ) )
96 p_intf->p_sys->p_fileopen = create_intf_fileopen();
97 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_fileopen ),
100 gtk_file_selection_set_filename( GTK_FILE_SELECTION(
101 p_intf->p_sys->p_fileopen ),
102 main_GetPszVariable( INTF_PATH_VAR, INTF_PATH_DEFAULT ) );
105 gtk_widget_show( p_intf->p_sys->p_fileopen );
106 gdk_window_raise( p_intf->p_sys->p_fileopen->window );
113 void GtkFileOpenCancel( GtkButton * button, gpointer user_data)
115 gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
118 void GtkFileOpenOk( GtkButton * button, gpointer user_data )
120 intf_thread_t * p_intf = GetIntf( GTK_WIDGET(button), "intf_fileopen" );
121 GtkCList * p_playlist_clist;
122 GtkWidget * p_filesel;
123 gchar * psz_filename;
124 int i_end = p_main->p_playlist->i_size;
126 /* hide the file selector */
127 p_filesel = gtk_widget_get_toplevel( GTK_WIDGET(button) );
128 gtk_widget_hide( p_filesel );
130 /* add the new file to the interface playlist */
132 gtk_file_selection_get_filename( GTK_FILE_SELECTION( p_filesel ) );
133 intf_PlaylistAdd( p_main->p_playlist, PLAYLIST_END, (char*)psz_filename );
135 /* catch the GTK CList */
136 p_playlist_clist = GTK_CLIST( gtk_object_get_data(
137 GTK_OBJECT( p_intf->p_sys->p_playlist ), "playlist_clist" ) );
138 /* update the plugin display */
139 GtkRebuildCList( p_playlist_clist, p_main->p_playlist );
141 /* end current item, select added item */
142 if( p_intf->p_input != NULL )
144 p_intf->p_input->b_eof = 1;
147 intf_PlaylistJumpto( p_main->p_playlist, i_end - 1 );
148 p_main->p_playlist->b_stopped = 0;
151 /*****************************************************************************
152 * Open disc callbacks
153 *****************************************************************************
154 * The following callbacks are related to the disc manager.
155 *****************************************************************************/
157 void GtkDiscOpenShow( GtkMenuItem * menuitem, gpointer user_data)
159 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), (char*)user_data );
161 if( !GTK_IS_WIDGET( p_intf->p_sys->p_disc ) )
163 p_intf->p_sys->p_disc = create_intf_disc();
164 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_disc ),
168 gtk_widget_show( p_intf->p_sys->p_disc );
169 gdk_window_raise( p_intf->p_sys->p_disc->window );
173 GtkDiscOpenShow (GtkWidget *widget,
174 GdkEventButton *event,
177 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), (char*)user_data );
179 if( !GTK_IS_WIDGET( p_intf->p_sys->p_disc ) )
181 p_intf->p_sys->p_disc = create_intf_disc();
182 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_disc ),
186 gtk_widget_show( p_intf->p_sys->p_disc );
187 gdk_window_raise( p_intf->p_sys->p_disc->window );
193 void GtkDiscOpenDvd( GtkToggleButton * togglebutton, gpointer user_data )
195 if( togglebutton->active )
198 GTK_ENTRY( lookup_widget( GTK_WIDGET(togglebutton), "disc_name" ) ),
199 main_GetPszVariable( INPUT_DVD_DEVICE_VAR, INPUT_DVD_DEVICE_DEFAULT )
204 void GtkDiscOpenVcd( GtkToggleButton *togglebutton, gpointer user_data )
206 if( togglebutton->active )
209 GTK_ENTRY( lookup_widget( GTK_WIDGET(togglebutton), "disc_name" ) ),
210 main_GetPszVariable( INPUT_VCD_DEVICE_VAR, INPUT_VCD_DEVICE_DEFAULT )
215 void GtkDiscOpenOk( GtkButton * button, gpointer user_data )
217 intf_thread_t * p_intf = GetIntf( GTK_WIDGET(button), "intf_disc" );
218 GtkCList * p_playlist_clist;
219 char * psz_device, *psz_source, *psz_method;
220 int i_end = p_main->p_playlist->i_size;
222 gtk_widget_hide( p_intf->p_sys->p_disc );
223 psz_device = gtk_entry_get_text( GTK_ENTRY( lookup_widget(
224 GTK_WIDGET(button), "disc_name" ) ) );
226 /* "dvd:foo" has size 5 + strlen(foo) */
227 psz_source = malloc( 3 /* "dvd" */ + 1 /* ":" */
228 + strlen( psz_device ) + 1 /* "\0" */ );
229 if( psz_source == NULL )
234 /* Check which method was activated */
235 if( GTK_TOGGLE_BUTTON( lookup_widget( GTK_WIDGET(button),
236 "disc_dvd" ) )->active )
240 else if( GTK_TOGGLE_BUTTON( lookup_widget( GTK_WIDGET(button),
241 "disc_vcd" ) )->active )
247 intf_ErrMsg( "intf error: unknown disc type toggle button position" );
252 /* Select title and chapter */
253 main_PutIntVariable( INPUT_TITLE_VAR, gtk_spin_button_get_value_as_int(
254 GTK_SPIN_BUTTON( lookup_widget(
255 GTK_WIDGET(button), "disc_title" ) ) ) );
257 main_PutIntVariable( INPUT_CHAPTER_VAR, gtk_spin_button_get_value_as_int(
258 GTK_SPIN_BUTTON( lookup_widget(
259 GTK_WIDGET(button), "disc_chapter" ) ) ) );
261 /* Build source name and add it to playlist */
262 sprintf( psz_source, "%s:%s", psz_method, psz_device );
263 intf_PlaylistAdd( p_main->p_playlist, PLAYLIST_END, psz_source );
266 /* catch the GTK CList */
267 p_playlist_clist = GTK_CLIST( gtk_object_get_data(
268 GTK_OBJECT( p_intf->p_sys->p_playlist ), "playlist_clist" ) );
270 /* update the display */
271 GtkRebuildCList( p_playlist_clist, p_main->p_playlist );
273 /* stop current item, select added item */
274 if( p_intf->p_input != NULL )
276 p_intf->p_input->b_eof = 1;
279 // vlc_mutex_lock( &p_main->p_playlist->change_lock );
281 intf_PlaylistJumpto( p_main->p_playlist, i_end - 1 );
282 p_main->p_playlist->b_stopped = 0;
284 // vlc_mutex_unlock( &p_main->p_playlist->change_lock );
287 void GtkDiscOpenCancel( GtkButton * button, gpointer user_data)
289 gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
292 /*****************************************************************************
293 * Network stream callbacks
294 *****************************************************************************
295 * The following callbacks are related to the network stream manager.
296 *****************************************************************************/
298 void GtkNetworkOpenShow( GtkMenuItem * menuitem, gpointer user_data)
300 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), (char*)user_data );
302 if( !GTK_IS_WIDGET( p_intf->p_sys->p_network ) )
304 p_intf->p_sys->p_disc = create_intf_network();
305 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_network ),
309 gtk_widget_show( p_intf->p_sys->p_network );
310 gdk_window_raise( p_intf->p_sys->p_network->window );
315 GtkNetworkOpenShow (GtkWidget *widget,
316 GdkEventButton *event,
319 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), (char*)user_data );
321 if( !GTK_IS_WIDGET( p_intf->p_sys->p_network ) )
323 p_intf->p_sys->p_network = create_intf_network();
324 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_network ),
328 gtk_widget_show( p_intf->p_sys->p_network );
329 gdk_window_raise( p_intf->p_sys->p_network->window );
338 void GtkNetworkOpenOk( GtkButton *button, gpointer user_data )
340 intf_thread_t * p_intf = GetIntf( GTK_WIDGET(button), "intf_network" );
341 GtkCList * p_playlist_clist;
342 char * psz_source, *psz_server, *psz_protocol;
344 boolean_t b_broadcast;
345 int i_end = p_main->p_playlist->i_size;
347 gtk_widget_hide( p_intf->p_sys->p_network );
348 psz_server = gtk_entry_get_text( GTK_ENTRY( lookup_widget(
349 GTK_WIDGET(button), "network_server" ) ) );
351 /* Check which protocol was activated */
352 if( GTK_TOGGLE_BUTTON( lookup_widget( GTK_WIDGET(button),
353 "network_ts" ) )->active )
357 else if( GTK_TOGGLE_BUTTON( lookup_widget( GTK_WIDGET(button),
358 "network_rtp" ) )->active )
360 psz_protocol = "rtp";
364 intf_ErrMsg( "intf error: unknown protocol toggle button position" );
368 /* Get the port number and make sure it will not 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), "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 ) + 1 /* ":" */
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 ) + 1 /* ":" */
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", psz_protocol, psz_server, i_port );
416 intf_PlaylistAdd( p_main->p_playlist, PLAYLIST_END, psz_source );
419 /* catch the GTK CList */
420 p_playlist_clist = GTK_CLIST( gtk_object_get_data(
421 GTK_OBJECT( p_intf->p_sys->p_playlist ), "playlist_clist" ) );
422 /* update the display */
423 GtkRebuildCList( p_playlist_clist, p_main->p_playlist );
425 /* select added item */
426 if( p_intf->p_input != NULL )
428 p_intf->p_input->b_eof = 1;
431 // vlc_mutex_lock( &p_main->p_playlist->change_lock );
433 intf_PlaylistJumpto( p_main->p_playlist, i_end - 1 );
434 p_main->p_playlist->b_stopped = 0;
436 // vlc_mutex_unlock( &p_main->p_playlist->change_lock );
439 void GtkNetworkOpenCancel( GtkButton * button, gpointer user_data)
441 gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
445 void GtkNetworkOpenBroadcast( GtkToggleButton * togglebutton,
448 GtkWidget * p_network;
450 p_network = gtk_widget_get_toplevel( GTK_WIDGET (togglebutton) );
452 gtk_widget_set_sensitive( gtk_object_get_data( GTK_OBJECT( p_network ),
453 "network_broadcast_combo" ),
454 gtk_toggle_button_get_active( togglebutton ) );
456 gtk_widget_set_sensitive( gtk_object_get_data( GTK_OBJECT( p_network ),
457 "network_broadcast" ),
458 gtk_toggle_button_get_active( togglebutton ) );