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.3 2001/05/23 23:08:20 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 /*****************************************************************************
27 *****************************************************************************/
29 #include <sys/types.h> /* off_t */
41 #include "stream_control.h"
42 #include "input_ext-intf.h"
44 #include "interface.h"
45 #include "intf_playlist.h"
48 #include "gtk_callbacks.h"
49 #include "gtk_interface.h"
50 #include "gtk_support.h"
51 #include "gtk_playlist.h"
56 /*****************************************************************************
58 *****************************************************************************
59 * The following callbacks are related to the file requester.
60 *****************************************************************************/
61 gboolean GtkFileOpenShow( GtkWidget *widget,
62 GdkEventButton *event,
65 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), (char*)user_data );
67 /* If we have never used the file selector, open it */
68 if( !GTK_IS_WIDGET( p_intf->p_sys->p_fileopen ) )
70 p_intf->p_sys->p_fileopen = create_intf_fileopen();
71 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_fileopen ),
74 gtk_file_selection_set_filename( GTK_FILE_SELECTION(
75 p_intf->p_sys->p_fileopen ),
76 main_GetPszVariable( INTF_PATH_VAR, INTF_PATH_DEFAULT ) );
79 gtk_widget_show( p_intf->p_sys->p_fileopen );
80 gdk_window_raise( p_intf->p_sys->p_fileopen->window );
86 void GtkFileOpenCancel( GtkButton * button, gpointer user_data )
88 gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
91 void GtkFileOpenOk( GtkButton * button, gpointer user_data )
93 intf_thread_t * p_intf = GetIntf( GTK_WIDGET(button), "intf_fileopen" );
94 GtkCList * p_playlist_clist;
95 GtkWidget * p_filesel;
97 int i_end = p_main->p_playlist->i_size;
99 /* hide the file selector */
100 p_filesel = gtk_widget_get_toplevel( GTK_WIDGET(button) );
101 gtk_widget_hide( p_filesel );
103 /* add the new file to the interface playlist */
105 gtk_file_selection_get_filename( GTK_FILE_SELECTION( p_filesel ) );
106 intf_PlaylistAdd( p_main->p_playlist, PLAYLIST_END, (char*)psz_filename );
108 /* catch the GTK CList */
109 p_playlist_clist = GTK_CLIST( gtk_object_get_data(
110 GTK_OBJECT( p_intf->p_sys->p_playlist ), "playlist_clist" ) );
111 /* update the plugin display */
112 GtkRebuildCList( p_playlist_clist, p_main->p_playlist );
114 /* end current item, select added item */
115 if( p_intf->p_input != NULL )
117 p_intf->p_input->b_eof = 1;
120 intf_PlaylistJumpto( p_main->p_playlist, i_end - 1 );
123 /*****************************************************************************
124 * Open disc callbacks
125 *****************************************************************************
126 * The following callbacks are related to the disc manager.
127 *****************************************************************************/
128 gboolean GtkDiscOpenShow( GtkWidget *widget,
129 GdkEventButton *event,
132 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), (char*)user_data );
134 if( !GTK_IS_WIDGET( p_intf->p_sys->p_disc ) )
136 p_intf->p_sys->p_disc = create_intf_disc();
137 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_disc ),
141 gtk_widget_show( p_intf->p_sys->p_disc );
142 gdk_window_raise( p_intf->p_sys->p_disc->window );
148 void GtkDiscOpenDvd( GtkToggleButton * togglebutton, gpointer user_data )
150 if( togglebutton->active )
153 GTK_ENTRY( lookup_widget( GTK_WIDGET(togglebutton), "disc_name" ) ),
154 main_GetPszVariable( INPUT_DVD_DEVICE_VAR, INPUT_DVD_DEVICE_DEFAULT )
159 void GtkDiscOpenVcd( GtkToggleButton * togglebutton, gpointer user_data )
161 if( togglebutton->active )
164 GTK_ENTRY( lookup_widget( GTK_WIDGET(togglebutton), "disc_name" ) ),
165 main_GetPszVariable( INPUT_VCD_DEVICE_VAR, INPUT_VCD_DEVICE_DEFAULT )
170 void GtkDiscOpenOk( GtkButton * button, gpointer user_data )
172 intf_thread_t * p_intf = GetIntf( GTK_WIDGET(button), "intf_disc" );
173 GtkCList * p_playlist_clist;
174 char * psz_device, *psz_source, *psz_method;
175 int i_end = p_main->p_playlist->i_size;
177 gtk_widget_hide( p_intf->p_sys->p_disc );
178 psz_device = gtk_entry_get_text( GTK_ENTRY( lookup_widget(
179 GTK_WIDGET(button), "disc_name" ) ) );
181 /* "dvd:foo" has size 5 + strlen(foo) */
182 psz_source = malloc( 3 /* "dvd" */ + 1 /* ":" */
183 + strlen( psz_device ) + 1 /* "\0" */ );
184 if( psz_source == NULL )
189 /* Check which method was activated */
190 if( GTK_TOGGLE_BUTTON( lookup_widget( GTK_WIDGET(button),
191 "disc_dvd" ) )->active )
195 else if( GTK_TOGGLE_BUTTON( lookup_widget( GTK_WIDGET(button),
196 "disc_vcd" ) )->active )
202 intf_ErrMsg( "intf error: unknown disc type toggle button position" );
207 /* Select title and chapter */
208 main_PutIntVariable( INPUT_TITLE_VAR, gtk_spin_button_get_value_as_int(
209 GTK_SPIN_BUTTON( lookup_widget(
210 GTK_WIDGET(button), "disc_title" ) ) ) );
212 main_PutIntVariable( INPUT_CHAPTER_VAR, gtk_spin_button_get_value_as_int(
213 GTK_SPIN_BUTTON( lookup_widget(
214 GTK_WIDGET(button), "disc_chapter" ) ) ) );
216 /* Build source name and add it to playlist */
217 sprintf( psz_source, "%s:%s", psz_method, psz_device );
218 intf_PlaylistAdd( p_main->p_playlist, PLAYLIST_END, psz_source );
221 /* catch the GTK CList */
222 p_playlist_clist = GTK_CLIST( gtk_object_get_data(
223 GTK_OBJECT( p_intf->p_sys->p_playlist ), "playlist_clist" ) );
225 /* update the display */
226 GtkRebuildCList( p_playlist_clist, p_main->p_playlist );
228 /* stop current item, select added item */
229 if( p_intf->p_input != NULL )
231 p_intf->p_input->b_eof = 1;
234 intf_PlaylistJumpto( p_main->p_playlist, i_end - 1 );
238 void GtkDiscOpenCancel( GtkButton * button, gpointer user_data )
240 gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
244 /*****************************************************************************
245 * Network stream callbacks
246 *****************************************************************************
247 * The following callbacks are related to the network stream manager.
248 *****************************************************************************/
249 gboolean GtkNetworkOpenShow( GtkWidget *widget,
250 GdkEventButton *event,
253 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), (char*)user_data );
255 if( !GTK_IS_WIDGET( p_intf->p_sys->p_network ) )
257 p_intf->p_sys->p_network = create_intf_network();
258 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_network ),
262 gtk_widget_show( p_intf->p_sys->p_network );
263 gdk_window_raise( p_intf->p_sys->p_network->window );
269 void GtkNetworkOpenOk( GtkButton *button, gpointer user_data )
271 intf_thread_t * p_intf = GetIntf( GTK_WIDGET(button), "intf_network" );
272 GtkCList * p_playlist_clist;
273 char * psz_source, *psz_server, *psz_protocol;
275 boolean_t b_broadcast;
276 int i_end = p_main->p_playlist->i_size;
278 gtk_widget_hide( p_intf->p_sys->p_network );
279 psz_server = gtk_entry_get_text( GTK_ENTRY( lookup_widget(
280 GTK_WIDGET(button), "network_server" ) ) );
282 /* Check which protocol was activated */
283 if( GTK_TOGGLE_BUTTON( lookup_widget( GTK_WIDGET(button),
284 "network_ts" ) )->active )
288 else if( GTK_TOGGLE_BUTTON( lookup_widget( GTK_WIDGET(button),
289 "network_rtp" ) )->active )
291 psz_protocol = "rtp";
295 intf_ErrMsg( "intf error: unknown protocol toggle button position" );
299 /* Get the port number and make sure it will not overflow 5 characters */
300 i_port = gtk_spin_button_get_value_as_int( GTK_SPIN_BUTTON(
301 lookup_widget( GTK_WIDGET(button), "network_port" ) ) );
304 intf_ErrMsg( "intf error: invalid port %i", i_port );
307 /* do we have a broadcast address */
308 b_broadcast = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(
309 lookup_widget( GTK_WIDGET(button), "broadcast_check" ) ) );
312 char * psz_broadcast;
313 psz_broadcast = gtk_entry_get_text( GTK_ENTRY( lookup_widget(
314 GTK_WIDGET(button), "network_broadcast" ) ) );
315 /* Allocate room for "protocol://server:port" */
316 psz_source = malloc( strlen( psz_protocol ) + 3 /* "://" */
317 + strlen( psz_server ) + 1 /* ":" */
319 + strlen( psz_broadcast ) + 2 /* "::" */
321 if( psz_source == NULL )
326 /* Build source name and add it to playlist */
327 sprintf( psz_source, "%s://%s:%i::%s", psz_protocol,
334 /* Allocate room for "protocol://server:port" */
335 psz_source = malloc( strlen( psz_protocol ) + 3 /* "://" */
336 + strlen( psz_server ) + 1 /* ":" */
337 + 5 /* 0-65535 */ + 1 /* "\0" */ );
338 if( psz_source == NULL )
343 /* Build source name and add it to playlist */
344 sprintf( psz_source, "%s://%s:%i", psz_protocol, psz_server, i_port );
347 intf_PlaylistAdd( p_main->p_playlist, PLAYLIST_END, psz_source );
350 /* catch the GTK CList */
351 p_playlist_clist = GTK_CLIST( gtk_object_get_data(
352 GTK_OBJECT( p_intf->p_sys->p_playlist ), "playlist_clist" ) );
353 /* update the display */
354 GtkRebuildCList( p_playlist_clist, p_main->p_playlist );
356 /* select added item */
357 if( p_intf->p_input != NULL )
359 p_intf->p_input->b_eof = 1;
362 intf_PlaylistJumpto( p_main->p_playlist, i_end - 1 );
365 void GtkNetworkOpenCancel( GtkButton * button, gpointer user_data)
367 gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
371 void GtkNetworkOpenBroadcast( GtkToggleButton * togglebutton,
374 GtkWidget * p_network;
376 p_network = gtk_widget_get_toplevel( GTK_WIDGET (togglebutton) );
378 gtk_widget_set_sensitive( gtk_object_get_data( GTK_OBJECT( p_network ),
379 "network_broadcast_combo" ),
380 gtk_toggle_button_get_active( togglebutton ) );
382 gtk_widget_set_sensitive( gtk_object_get_data( GTK_OBJECT( p_network ),
383 "network_broadcast" ),
384 gtk_toggle_button_get_active( togglebutton ) );
389 /****************************************************************************
390 * Callbacks for menuitem
391 ****************************************************************************/
392 void GtkFileOpenActivate( GtkMenuItem * menuitem, gpointer user_data )
394 GtkFileOpenShow( GTK_WIDGET( menuitem ), NULL, user_data );
398 void GtkDiscOpenActivate( GtkMenuItem * menuitem, gpointer user_data )
400 GtkDiscOpenShow( GTK_WIDGET( menuitem ), NULL, user_data );
404 void GtkNetworkOpenActivate( GtkMenuItem * menuitem, gpointer user_data )
406 GtkNetworkOpenShow( GTK_WIDGET( menuitem ), NULL, user_data );